Share via


SharePoint Online Office 365 create a provider hosted add-in and host in Microsoft Azure using Microsoft Azure Web Apps method

Introduction:

Here we will discuss how we can create a provider-hosted add-in using visual studio 2015 for SharePoint online 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.

Detailed Steps:

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-sharepoint-online-1.png

Then choose a SharePoint developer site and then choose Provider-hosted like below. You can see below article to know how we can create developer site in SharePoint.

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-sharepoint-online-office-365-2.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-sharepoint-online-office-365-1-1.png

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.

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-sharepoint-online-visual-studio-1.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-sharepoint-online-visual-studio-2015-1.png

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.

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-sharepoint-online-vs-2015-1.png

Here we are not modifying the default code which is displaying the current username (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:

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/create-provider-hosted-add-in-sharepoint-online-vs-2015-1.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/publish-provider-hosted-add-in-azure-1.png

Here we will use the "Microsoft Azure Web Apps" option to deploy the project to Azure.

Before procedeing further we need to create a web site in Microsoft Azure. Let us follow below article for the same.

Once the website is ready, follow below step.

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 website which we have created in Azure (without https://). And the Redirect URI put the website URL, make sure to  give in https:

Here the page looks like below:

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/create-publish-provider-hosted-add-in-azure1-1.png

Then open the web.config file and replace the ClientId and ClientSecret which we have generated in the above page.

It looks like below:

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/how-to-create-provider-hosted-add-in-sharepoint-online-1.png

Now right click on the web project and click on Publish. Then choose the Microsoft Azure Web Apps option like below: 
 

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/deploy-provider-hosted-add-in-microsoft-azure-web-apps.png

Then click on OK.

Then login to your Azure account, Once you login, it will populate all the existing web apps. Choose the one which we have created in the above step. Here also you can directly create a web app, if you have not created before.

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/deploy-provider-hosted-add-in-microsoft-azure-web-apps-sharepoint.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/how-to-create-provider-hosted-add-in-sharepoint-online-using-visualstudio-2015-2.png

Click on Next.

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-publish-azure-1.png

It will take some time to publish.

Once it is successfully deployed, Now right click on the Addin project like below:

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/sharepoint-online-provider-hosted-add-in-1-1.png

Here click on the Edit button 

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/sharepoint-online-provider-hosted-add-in-visual-studio-1-1.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/sharepoint-online-provider-hosted-add-in-visual-studio-2015-1-1.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-package-1-1.png

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

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/provider-hosted-add-in-package-sharepoint-online-1-1.png

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.

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/Deploy-provider-hosted-add-in-developer-site-1-1.png

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.

https://www.enjoysharepoint.com/wp-content/uploads/2018/09/Deploy-provider-hosted-add-in-developer-site-visual-studio-2015-1.png

Conclusion:

Here we have discussed how we can develop a SharePoint provider hosted add-in using visual studio 2015 and how we can deploy it to Microsoft Azure.