Jul 23, 2012

Building ASP.NET MVC based SharePoint Cloud Apps

When you either create an auto-hosted or a provider hosted app, Visual Studio automatically generates an ASP.NET Forms project for you. Do you really want an ASP.NET Forms project? Many web developers would say no! They would prefer ASP.NET MVC. Anyway each of this two models has his advantages and disadvantages. Discussing this in detail would be out of scope for this post. Personally I think ASP.NET MVC and SharePoint Apps fit together really good. In this post I’m going to show step by step how to create an ASP.NET MVC based SharePoint app.

Create the SharePoint App

Create either an auto-hosted or provider hosted SharePoint 2013 App. For this example I’ve chosen auto-hosted. As development system I use a local Visual Studio with an Office 365 developer site.

image

Visual Studio will generates the following solution structure for you. Including a SharePoint App project and an ASP.NET Forms Web project.

image 

We prefer ASP.NET MVC. So let’s add an ASP.NET MVC (.NET 4.0) project to the solution. The Azure tenant currently supports only .NET 4.0.

SNAGHTML24bc897

SNAGHTMLb72629

In the SharePoint App property windows choose the ASP.NET MVC project as that associated web project.

image

One of the most challenging tasks of app development is the authentication. To help you with this Microsoft added a Token Helper class to the auto-generated ASP.NET Forms project. We want use the Token Helper too, so let’s copy the TokenHelper.cs file to our ASP.NET MVC project.

image

If you want to, you can change the namespace of the TokenHelper.cs to fit the project default namespace.

To be able to build the project you need to add some new references to the ASP.NET MVC project.

  • Microsoft.IdentityModel
  • Microsoft.IdentityModel.Extensions (if you don’t find the reference, copy the path from the ASP.NET Forms project and choose browse in reference dialog)
  • System.IdentityModel

This is be able to build again. But it very likely that you also want to callback to SharePoint, so add the references for the ClientOM.

  • Microsoft.SharePoint.Client
  • Microsoft.SharePoint.ClientRuntime

You have to set the copy local property of all the above references to true. 

We also need to enable SSL on our MVC project. If we would forget this, SharePoint would not send a Context Token. OAuth 2.0 requires SSL.

image

It is also useful to set the MVC project to “Don’t open page…”

image

Right click Controllers folders in the MVC project and add a new controller.

SNAGHTMLda8c0d

Add the following code to the controller:

image

Within the Views folder create a new sub folder called “Home”. Right click the folder and choose and add a new View:

image

Add the following code to the view:

image

Set the start page of our app to this view. To do this you have to switch to the code view of AppManifest.xml.

image

Now you can start the app for the first time. Hit F5, trust and start the app.

image

You have just created your first ASP.NET MVC based SharePoint App.

Note that during the first run Visual had added a Client Id and a Secret to the web.config of our ASP.NET MVC project.

image

When everything works as expected you can now delete the old ASP.NET Forms project.

Add SharePoint Look and Feel to the App

We are now going to add the ShareCoint chrome to our MVC site. Under Views->Shared modify _layouts.cshtml as follows:

image

Don’t panic, you can download the source code here.

Right click the app project and click deploy to deploy the app to Office 365. In the background tha ASP.NET MVC project will automatically provisioned to Windows Azure. The app should now look like this:

image

Wish you a lot fun with SharePoint Apps & ASP.NET MVC.

Cheers,

Christian

426 comments:

«Oldest   ‹Older   401 – 426 of 426
Alice Taylor said...

This is a great article. It gave me a lot of useful information. thank you very much.

http://word-cookies-answers.com

raybanoutlet001 said...

coach outlet store
jordan shoes
new balance shoes
ugg outlet
hugo boss sale
nba jerseys
cheap nfl jerseys
michael kors uk
adidas nmd
ugg outlet

John Fernando said...

The old lottery result of the Sambad are as follows : Lottery Sambad old result

Easy to access the old result of Lottery for Nagaland : Nagaland Lotteries old result by just clicking on this link

Nice to get the old lottery result of Sikkim : Sikkim Lotteries old result on this click

We will get the old lottery result of Mizoram on our finger tip :Mizoram Lotteries old result through clicking this link

Construction Company City of Yonkers said...

The team at Ajrin Construction Inc. is the best of the best general contractors and support staffs, as selected from within the industries over City of Yonkers NY based upon their achievements and their understanding of complex projects.

John Fernando said...

We will get the old lottery result of Sambad on our finger tip :Lottery Sambad old result through clicking this link

Nice to get the old lottery result of Nagaland: Nagaland Lotteries old result on this click

Easy to access the old result of Lottery for Sikkim: Sikkim Lotteries old result by just clicking on this link

The old lottery result of the Mizoram are as follows : Mizoram Lotteries old result

Anonymous said...

Awesome Post!
Check out Reason Behind Diya HD pictures 2017
Also download latest movie COMMANDO 2 (2017) DESI PDVD NTSC AC3 EXHD EXCLUSIVE
Also Read trending Story Shocking Snapchat Screenshots
Also Check out Latest vacancy of Government Job Govt. Rajasthan RecruitmenT 2017

John Fernando said...

It is very good information that we will get details : Bigg Boss 11 on one single click

Seems to nice to watch the show :Watch Bigg Boss 11 on our finger touch

We will get details of contestant of the Big Boss show :Bigg Boss 11 Contestants on single shot

Nice to hear the details such as Voot Bigg Boss 11 of the show.

The complete details of audition of this show :Bigg Boss 11 Audition will give complete information

Thu Lê said...

I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post. Keep working, great job! In my free time, I like play game: vex3game.com. What about you?

Games 2 Girls said...

This article is really fantastic and thanks for sharing the valuable post.
run3unblockedgame.com

mariam said...

garden shed nz
new garden sheds

KAOS FULL PRINT said...

Thanks for your information

شركة المثالية للتنظيف said...


شركة المثالية للتنظيف تسعد بتقديم خدماتها لعملائها بالمنطقة الشرقية خدمات تنظيف خدمات مكافحة حشرات خدمات تسليك مجاري المياه للمطابخ والحمامات جميع الخدمات المنزلية تجدونها مع شركة المثالية للتنظيف بافضل جودة وارخص الاسعار بالاعتماد علي كافة الادوات الحديثة والعمالة الماهرة

شركة المثالية للتنظيف
شركة المثالية للتنظيف بالدمام
شركة المثالية للتنظيف بالخبر

شركة المثالية للتنظيف بالجبيل
شركة المثالية للتنظيف بالقطيف

تواصلوا معنا للحصول علي خدمات شركة المثالية للتنظيف ومعرفة اسعارها المميزة وخدماتها بجميع مدن ومحافظات المنطقة الشرقية علي جوال 0577017188 نصلكم اينما كنتم

شركة المثالية للتنظيف said...


شركة المثالية للتنظيف بالاحساء
شركة المثالية للنظافة
شركة المثالية الدولية للتنظيف
شركة المثالية للتنظيف بسيهات
شركة المثالية للتنظيف بجدة

شركة تنظيف مسابح بالقطيف
شركة صيانة مسابح بالقطيف
شركة تنظيف مسابح بالدمام

شركة المثالية للتنظيف said...


شركة تنظيف بيوت بالقطيف
شركة تنظيف بالقطيف

شركة تنظيف منازل بالقطيف
شركة تنظيف شقق بالقطيف

شركة المثالية للتنظيف said...


شركة تنظيف منازل بالخبر
شركة تنظيف بالخبر
شركة تنظيف شقق بالخبر
شركة تنظيف فلل بالخبر
شركة تنظيف مسابح بالخبر
شركة صيانة مسابح بالخبر

شركة تنظيف كنب بالخبر
شركة تنظيف مكيفات بالخبر
شركة صيانة مكيفات بالخبر
شركة تنظيف مطابخ بالخبر

شركة المثالية للتنظيف said...



شركة تنظيف بالاحساء
شركة تنظيف منازل بالاحساء
شركة تنظيف شقق بالاحساء
شركة تنظيف مجالس بالاحساء
شركة تنظيف مسابح بالاحساء
شركة صيانة مسابح بالاحساء

شركة تسليك مجاري بالاحساء
شركة تنظيف خزانات بالاحساء
شركة شفط بيارات بالاحساء
شركة نقل عفش بالاحساء

**

John Fernando said...

We will get complete informations of Karnataka SSLC Results :karresults.nic.in by clicking this link

This is very easy to get the details of Karnataka SSLC Results : Karnataka SSLC Result on this link

Please find complete details of results of Karnakaka SSLC : SSLC Result 2018 thru this link

For the information regarding the results of Karnakaka SSLC 2018 : Karnataka SSLC Results 2018 This will be helpful

gujratlion said...

bigg boss 11
Bigg boss whatsapp status
whatsapp status
Happy diwali
good morning wishes
gujrat lion
Gujrati Singer

John Fernando said...

We will get all dtails of TN SSLC result:tnresults.nic.in by just a click

This is nice information of TN SSLC result:Tamilnadu SSLC Result for a click on this link

This gives details of SSLC result : SSLC Result 2018 on a click

Complete TN SSLC result : Tamilnadu SSLC Results 2018 on your finger tip

gujratlion said...

bigg boss 11
Bigg boss whatsapp status
whatsapp status
Happy diwali
good morning wishes
gujrat lion
Gujrati Singer
Mahesh Babu Dialouge
Click here
good morning wallpaper
diwali 2017 good morning
Diwali Wishes
Christmas wishes

Aavuj Reshe Gujrati Movie
Upcoming gujrati Movie
Jigli And khajur
Khajur & Jigli
Gujrati Comedy Video
Kabutri and Popat
Popat & kabutri
Gujrati Comedy Videos
Aavuj Reshe Movie Box Office Collection

John Fernando said...

Complete Kerala HSC results : keralaresults.nic.in on your finger tip

This gives details of HSC results : Kerala HSC Result on a click

This is nice information of Kerala HSC results 2018:HSC Result 2018 for a click on this link

We will get all details of Kerala HSC results :Kerala HSC Results 2018 by just a click

ngocanhng said...

I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
Very interesting blog.
www.baixarfacebookgratis.com.br

Miss Twetty said...

Stress Relief Tips
Ways to fall asleep faster
High Protien Foods List
christmas healthy tips
Chocolate Facts
Interesting Facts About American Culture

John Fernando said...

Nice to see all TNHSC results tnresults.nic.in in one click

This is super information regarding TNHSC results Tamilnadu HSC Result on simple link

It is very much interesting to get HSC results 2018 of TN HSC Result 2018 on your fingertip

We are very much eager to get this info on Tamilnadu HSC Results 2018 of TN HSC results throught this link

Garrick Co Ida said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

Holly Peppers said...

it's very easy to finding U.S. http://www.unitedcheckcashing.com as we've an inclination to unit at your city or nearest places. merely confine mind U.S. which we are able to cash your check very short quantity with a awfully low price.check cashing

«Oldest ‹Older   401 – 426 of 426   Newer› Newest»