How to create provider hosted app in SharePoint Online step by step

provider hosted app in sharepoint 2013 deployment
SharePoint deveopment training course

This SharePoint Online tutorial explains how to create a provider hosted add-in (Apps) SharePoint Online using Visual Studio. We will also see how to deploy provider hosted add-in or apps to Microsoft Azure.

I have used Visual Studio 2015, here but the same steps can be followed to create a provider hosted app using visual studio 2017/2019.

SharePoint Provider Hosted Add-ins contains components that are deployed and hosted outside SharePoint farm.

A provider hosted add-in, include a web application, service, or database that is hosted externally from the SharePoint farm or SharePoint Online subscription. They may also include SharePoint components.

The custom business logic in the add-in has to run on either the external components or in JavaScript on custom SharePoint pages.

You can develop provider hosted add-in for SharePoint 2013/2016 on-premise, but here we will see how we can develop provider hosted add-in for SharePoint Online and how to host in Microsoft Azure.

Create provider hosted app in SharePoint Online step by step

Follow below steps to create provider hosted add-in or add in SharePoint Online.

Open visual studio 2015/2017 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.

provider hosted app in sharepoint

Then choose a SharePoint developer site and then choose Provider-hosted like below. Developer site is a must if you are trying to create any apps or add-in in SharePoint.

provider hosted app 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:

provider hosted app in sharepoint online office 365

Then in the web project type, select whether you want to create an ASP.NET web Forms Application or ASP.NET MVC Web Application like below. Here we will choose ASP.NET MVC Web Application. You can select based on your expertise.

sharepoint provider hosted app in sharepoint online step by step

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

sharepoint provider hosted app register

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

sharepoint provider hosted app example

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:

sharepoint provider hosted app deployment steps

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

sharepoint provider hosted app example

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. And once the web site created successfully, then we need to get the published profile for the particular Azure web site. You can follow the below article to create the web app in Microsoft Azure and download the publish profile. Download and Save in the same machine.

Once you downloaded the publish profile, 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:

create sharepoint provider hosted app step by step

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

sharepoint provider hosted app in azure

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

create sharepoint provider hosted app step by step

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

how to create provider hosted app in sharepoint 2013 step by step

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

how to create provider hosted app in sharepoint online step by step

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

how to create provider hosted app in office 365

Here click on the Edit button.

how to create provider hosted app in sharepoint 2013 step by step

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

how to create provider hosted apps in sharepoint online

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

how to create provider hosted app

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

create provider hosted app sharepoint online

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.

create sharepoint provider hosted app step by step

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.

Create provider hosted app in SharePoint Online step by step

You may like following SharePoint Apps tutorials:

This SharePoint tutorial explains, how to create a provider hosted app or add-in in SharePoint Online using visual studio 2015/2017/2019.

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 →