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

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/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.

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.

  • Steps to create a web site in Microsoft Azure for SharePoint Online
  • How to get publish profile for Microsoft Azure web site?

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

Web deployment task failed. Could not connect to the remote computer using the specified process

SharePoint provider hosted add-in error web deployment task failed Could not connect to the remote computer using the specified process

Recently while deploying provider hosted add-in to Microsoft Azure, I got the below error which says: Web deployment task failed. (Could not connect to the remote computer (“mywebsite.scm.azurewebsites.net”) using the specified process (“Web Management Service”) because the server did not respond.

Make sure that the process (“Web Management Service”) is started on the remote computer. Learn more at: http:go.microsoft.com.link#ERROR_COULD_NOT_CONNECT_TO_REMOTESVC.)

The error looks like below:

Web deployment task failed. Could not connect to the remote computer using the specified process

Sometimes due to network issues, the error comes when we try to connect to the Azure environment. Try two-three times it will publish successfully.

you are being redirected to the following URL that was not registered as the app launch URL

Let us see how to fix an error that occurs when you click on any app or add-in in SharePoint 2013, you are being redirected to the following URL that was not registered as the app launch URL.

You are being redirected to the following URL that was not registered as the app launch URL https://siteurl?SPHostUrl=hostweburl&amp;SPLanguage=enSPClientTag=0&amp;SPProductNumber=xx&amp;SPAppWebUrl=url&amp;{AppContextToken}. If you trust this URL, click here to proceed to the app now. Otherwise, go back to the previous page or close this page.”

We have developed and deployed a SharePoint provider hosted add-in and when we click on the app, it showing the warning message which is difficult for the end-user to understand.

you are being redirected to the following url that was not registered as the app launch url
you are being redirected to the following url that was not registered as the app launch url

you are being redirected to the following URL that was not registered as the app launch URL

If you have changed the domain name or you have moved your app (provider hosted app to any other IIS server) then you also need to update in the App registration page.

sharepoint 2013 app redirect not working
sharepoint 2013 app redirect not working

Check below article

you are being redirected to the following URL that was not registered as the app launch URL SharePoint Apps

If you are getting the error in SharePoint 2013 on-premise, then you can run the below PowerShell command:

Add-PSSnapin Microsoft.SharePoint.PowerShell
$farm = Get-SPFarm
$farm.Properties["CustomAppRedirect"] = $true
$farm.Update()

After this, the error you are being redirected to the following URL that was not registered as the app launch URL will not come.

You may like the 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.

>