Create a Windows Azure Auto-Hosted App in SharePoint 2013

Wouldn’t it be awesome if you could deploy server side code to your office 365 tenant? Yes, it would! And with Windows Azure Auto-Hosted apps in SharePoint 2013 it is possible! This is amazing! I feel a little bit sorry for all the competitors. With the possibility to run server side code within Office 365 there are only few reasons to run SharePoint on premise. Especially midsize companies should consider really well to migrate to Office 365.

To get this working internally each Office 365 gets automatically an Azure account associated. More details about the architecture and billing will follow until the RTM.

In an azure auto-hosted app you can include:

  • Web Projects (Shared IIS Hosting)
  • SQL Azure Databases

Overview

Image _thumb [15]_thumb

  1. Create a Windows Azure Auto-Hosted App in Visual Studio 2013
  2. Deploy to SharePoint
  3. Add the App to a site
  4. SharePoint automatically provisions the Azure Website and the SQL Azure DBs that are included in the app package on the associated Azure tenant.

Execution Flow

 Image _thumb [17]_thumb

  1. User clicks app “A”, SP loads app specific page “B”
  2. Content Area “B” loads Windows Azure page
  3. Azure executes Code
  4. Azure can interact with SharePoint using Client Object Model (CSOM) and OData Services.
  5. Azure app can utilize SQL Azure DBs
  6. Azure app can interact with external services “C”
  7. Azure app can interact with the host site.

 

Let’s give it a try…

Create a SharePoint 2013 App in Visual Studio 2012 (don’t forget to start Visual Studio as an admin).

SNAGHTML10d 7717_thumb [4]_thumb

Enter the name of the app, the URL of your development site and choose “Autohosted“. For this app you do not need a local SharePoint Installation! I’ve used a developer site within the SharePoint Online 2013 preview.

SNAGHTML10e 341f _thumb [6]_thumb

Visual Studio will generates two projects. “SPAutohostedApp” constains the AppManifest for your remote app and SPAutohostedAppWeb is an ASP.NET Forms that projects that hosts your ASP.NET code. The included class “TokenHelper.cs” will do all the OAuth 2.0 magic for you.

Image _thumb [20]_thumb

The AppManifest.xml the defines the startpage of your remote app. “~remoteAppUrl” will be replaced with the url of your dynamically hosted web application. In the AppPrerequsites is defined that your web application should be automatically provisioned to azure .

Image _thumb [51]_thumb

Default.aspx includes sample code how to handle OAuth 2.0 authentication with the help of “TokenHelper” and how to callback to SharePoint using CSOM.
Image _thumb [24]_thumb

Press F5.

Trust the app.

Image _thumb [26]_thumb

Launch the app.

Image _thumb [28]_thumb

Image _thumb [39]_thumb

In debug mode the app will not be auto provisioned to azure. Visual Studio starts IIS Express to host and debug your ASP.NET website locally. When you launch the app in SharePoint Online the app url refers to localhost and you can debug your code. This is really handy.

Image _thumb [33]_thumb

Deploy the App

Now we’re going to deploy the app instead of debugging.

Image _thumb [36]_thumb

Trust and launch the app.

Image _thumb [39]_thumb

Checkout the URL. The website has automatically be provisioned to Azure! Awesome!

Create An App Package

In order to publish the app to your company’s app catalog or to the public marketplace you can build an app package.

Image _thumb [50]_thumb

Image _thumb [49]_thumb

Done.

This article by Christian Glessner was first published on iLove SharePoint. Check out our resource centre for more SharePoint content from Christian and other SharePoint specialists!

Register now and be part of the European SharePoint Conference 2013. 

Share this on...

Rate this Post:

Share: