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.
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.
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.
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.
Then it will ask to give credentials for the developer site and then it will automatically select the SharePoint version like below:
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.
Then choose “Use Windows Azure Access Control Service (for SharePoint cloud apps)” in the Configure authentication settings like below:
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.
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:
This will open the Publish Web dialog box which looks like below:
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:
Then open the web.config file and replace the ClientId and ClientSecret which we have generated in the above page. It looks like below:
Now right-click on the web project and click on Publish. Then choose the import option.
Then click on OK. This will open the below screen. Give the destination URL as https://enjoysharepoint.azurewebsites.net as shown as below:
Click on Next. Then click on Next and finally click on Publish like below:
It will take some time to publish. Once it is successfully deployed, Now right click on the Addin project like below:
Here click on the Edit button.
Here in the Web Deploy dialog box give the clientid and client secret like below:
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:
This will show the URL and ClientId, here click on Finish button which will generate the app file.
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\188.8.131.52
Here I have uploaded to the Apps in Testing library in my developer site.
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.
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:
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 may like following SharePoint Apps tutorials:
- SharePoint Hosted Apps: Create Choice Type Column in SharePoint Online Office 365
- Set up an On-Premise development environment for SharePoint Add-in or Apps development in SharePoint 2016/2013
- Debug SharePoint Hosted or Provider hosted Add-in in a different browser in visual studio
- Develop SharePoint workflows using visual studio as SharePoint hosted App
- Error occurred in deployment step Install SharePoint Add-in Sideloading of apps is not enabled on this site
This SharePoint tutorial explains, how to create a provider hosted app or add-in in SharePoint Online using visual studio 2015/2017/2019.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com