Steps to create a provider hosted add-in in SharePoint Online and host in Microsoft Azure using Import method

provider hosted app in sharepoint 2013 deployment

This SharePoint online tutorial explains how we can create a provider hosted add-in using visual studio 2015 for SharePoint online (Download PDF for FREE) site and how we can host it in Microsoft Azure. SharePoint Provider Hosted Add-ins contains components that are deployed and hosted outside SharePoint farm. Here we will discuss how we can host in Microsoft Azure.

Follow below steps:
Open visual studio 2015 and then File -> New Project. Then in the New Project dialog box, choose Templates -> Visual C# -> Office/SharePoin and from there choose App for SharePoint like below. Give a name and make sure .Net Framework version should be choosen 4.5.



SharePoint deveopment training course
SharePoint online create provider hosted add-in using visual studio 2015
SharePoint online create provider hosted add-in using visual studio 2015

Then choose a SharePoint developer site and then choose Provider-hosted like below. You can see below article on developer site in SharePoint.

how to create provider hosted add-in using visual studio 2015 in SharePoint Online
how to create provider hosted add-in using visual studio 2015 in SharePoint Online




Then it will ask to give credentials for the developer site and then it will automatically select the SharePoint version like below:

Deploy provider hosted add-in SharePoint online using visual studio 2015
Deploy provider hosted add-in SharePoint online using visual studio 2015

Then in the web project type, select whether you want to create a ASP.NET web Forms Application or ASP.NET MVC Web Application like below. Here we will choose ASP.NET MVC Web Application.

provider hosted app in sharepoint 2013
provider hosted app in sharepoint 2013

Then choose “Use Windows Azure Access Control Service (for SharePoint cloud apps)” in the Configure authentication settings like below:

provider hosted app in sharepoint 2013 online
provider hosted app in sharepoint 2013 online

Visual studio will take sometime and will create two projects one (Add-in and another one is the ASP.NET MVC Web project) like below.

provider hosted app in sharepoint 2013 deployment
provider hosted app in sharepoint 2013 deployment

Here we are not modifying the default code which is displaying the current user name (presented in HomeController.cs file).

Now we will try to publish the provider hosted-add-in to Microsoft Azure.

Right click on the Web project and click on Publish like below:


provider hosted app in sharepoint 2013 online step by step
provider hosted app in sharepoint 2013 online step by step

This will open the Publish Web dialog box which looks like below:

provider hosted app in sharepoint 2013 on premise
provider hosted app in sharepoint 2013 on premise

Here we will use the import option to deploy the project to Azure.

Before proceeding further we need to create a web site in Microsoft Azure. You can follow the below article for the same.

Steps to create a web site in Microsoft Azure for SharePoint Online

Once the web site created successfully, then we need to get the published profile for the particular Azure web site. You can follow below article to get the profile. Download and Save in the same machine.

How to get publish profile for Microsoft Azure web site?

Once the file is ready, follow below steps.

Open the _layouts/15/appregnew.aspx url in the developer site.

There click on the Generate button for the Client Id and Client Secret fields. Then give a title and Domain put the web site which we have created in Azure (without https://). And the Redirect URI put the web site url, make sure to give in https:

Here the page looks like below:

sharepoint provider hosted app visual studio 2013
sharepoint provider hosted app visual studio 2013

Then open the web.config file and replace the ClientId and ClientSecret which we have generated in the above page. It looks like below:

provider hosted app in sharepoint 2013 authentication
provider hosted app in sharepoint 2013 authentication

Now right click on the web project and click on Publish. Then choose the import option.

provider hosted app in sharepoint 2016
provider hosted app in sharepoint 2016

Then click on OK. This will open the below screen. Give the destination url as https://enjoysharepoint.azurewebsites.net as shown like below:

provider hosted app in sharepoint 2016 deployment
provider hosted app in sharepoint 2016 deployment

Click on Next. Then click on Next and finally click on Publish like below:



SharePoint provider hosted apps visual studio
SharePoint provider hosted apps visual studio

It will take some time to publish.
Once it is successfully deployed, Now right click on the Addin project like below:

SharePoint provider hosted apps visual studio 2015
SharePoint provider hosted apps visual studio 2015

Here click on the Edit button

visual studio 2015 create provider hosted apps sharepoint
visual studio 2015 create provider hosted apps sharepoint

Here in the Web Deploy dialog box give the clientid and client secret like below:

SharePoint provider hosted add in visual studio
SharePoint provider hosted add in visual studio

For the safe side click on the Deploy yur web project button. Now once it is deployed successfully, click on the Pakag the app button which is presented below:

SharePoint provider hosted add in visual studio 2015
SharePoint provider hosted add in visual studio 2015

This will show the URl and ClientId, here click on Finish button which will generate the app file.

visual studio 2015 create provider hosted add in sharepoint
visual studio 2015 create provider hosted add in sharepoint

Now we can upload the .app file into the app catalog site or in the developer site. The .app file will get generated in the below location.
C:\Users\<username>\Documents\visual studio 2015\Projects\OurDemoPoviderHostedAddin\OurDemoPoviderHostedAddin\bin\Debug\app.publish\1.0.0.0

Here I have uploaded to the Apps in Testing library in my developer site.

sharepoint online provider hosted add-in
sharepoint online provider hosted add-in

Once it is installed successfully, when you click on the app, the Azure site will open and it will display the user name like below.

SharePoint 2013 provider hosted add-in visual studio
SharePoint 2013 provider hosted add-in visual studio

Read some sharepoint online tutorials:

Hope this will be helpful for provider hosted app in sharepoint online.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

View all posts by Bhawana Rathore →