Provider-hosted Apps for SharePoint Online in Azure Website

In SharePoint 2013 Online, there are a lot of limitations due to the cloud server and shared resources. One of the limitations is the sandbox solution can only execute within 30 seconds, and timeout if the process exceed that threshold. This is a bad news for enterprise users, especially the client want to execute tasks vary. even through 5% of of the tasks cannot finish in 30 seconds, they would have to find an alternative way.

To resolve this issue, one of the wokr around is host your SharePoint apps in remote web application, it can be a cloud web, or on-premises, and connect it to your SharePoint online server, so that the process can execute on remote web server which don’t have the limitation. In this case the app is installed just as a reference in SharePoint Online and all the code is executed in your hosting provider.

In this article I will use Azure website as the remote hosted website to connect to SharePoint online.

the detailed steps:

before start the development, make  sure you have already setup a SharePoint Online site and a Azure website

1. create the solution: create a new solution, select the template from Visual C# -> Office/SharePoint -> Apps -> App for SharePoint 2013. there are two projects :  one for SharePoint app, one for remote components

Image

2. go to your SharePoint Online and register your app with AppRegNew.aspx (/_layouts/15/appregnew.aspx), note down the App Id and App secret. the Title will be the App Title, App Domain is the website URL of the AZure website, and redirect URI is the url of the SharePoint App will be deployed to. It should be /Pages/Default.aspx by default.

Image

3. Update the SharePoint App project.

1. the AppManifest.xml should look like this

Image

2. Add Key/value pair for ClientId and ClientSecret to AppSettings in web.config

Image

4. after development finsihed, publish the ASP.NET website to Azure – using WebDeploy here:

1. download the publish profile from Azure website

Image

2. Publish the Website

Image

3. Import the publish profile in step 1

Image

4. Once the settings in the Publish Profile have been validated, click “Publish” to deploy to your Azure site. The remote components are now deployed to Azure.

Image

5. Publish the SharePoint App to SharePoint Online

1. Publish the SharePoint App, enter the Azure website URL, and the ClientId, ClientSecret of the SharePoint Online site, which is the AppId and App Secret from Register App step

Image

2. at this point, after the publish finish, the app file is saved to local machine. and the app is ready and can be added to the App Catalog in your SharePoint 2013. Go to “Apps for SharePoint” library within the associated App catalog site, and either upload the .app file, or drag in:

Image

3. Now the app can be added to your site:

Image

Now you have remote code running and have a location to host it.

For more informations related to this, please refer to http://www.sharepointnutsandbolts.com/2013/07/deploying-sp2013-provider-hosted.html