3. Autohosted App Deployment
Autohosted application deployment is
almost as straightforward as SharePoint-hosted application deployment.
This is because SharePoint Online takes care of all the heavy lifting
deploying the code and database packages to Azure for you as well as
creating and managing client IDs and secrets.
In the following exercise you will give creating
a simple Autohosted app a go and deploy it into SharePoint Online using
a private app catalog.
Deploying an Autohosted App
In this example you create a very
basic SharePoint Autohosted application using Visual Studio. You need a
SharePoint Online tenant set up as well as the app catalog created from
the previous exercise, “Creating a Private App Catalog in Office 365,”
prior to starting this exercise.
1. Create a
new SharePoint app in Visual Studio using the App for SharePoint 2013
template by selecting File ⇒ New Project ⇒ App for SharePoint 2013.
2. Enter the name of your app in the first box; for example, MyAutoHostedApp.
3. Enter the URL to your SharePoint Online developer site.
4. Select Autohosted from the app type drop-down list. When you have completed the form it should look similar to Figure 22.
5. Click Finish.
6. Right-click the Web project in the solution and select Publish.
7. Click Next. A summary page appears like the one shown in Figure 23.
8. Click Finish. Once the wizard completes a new Windows Explorer window opens with your application package called MyAutoHostedApp.app showing.
9. Open a browser window and navigate to the tenant admin portal for your Office 365 environment at: http://portal.microsoftonline.com.
10. Under the Admin menu in the top navigation, click SharePoint to go to the SharePoint Online tenant admin pages.
11. Click Apps in the left-side navigation.
12. Click the App Catalog link.
13. Click the Distribute apps for SharePoint tile.
14. Click the New App button. A prompt appears asking you to pick the .app file for your application.
15. Click Browse and select the
.app
file that Visual Studio packaged for you in step 8. Click OK. A dialog
appears asking you to enter information about your application, as
shown in Figure 24.
16. You are
not required to enter any information, but if you want, enter the
information and then click Save to proceed. You should now see your
SharePointAutoHostedApp application in the app catalog.
17. Navigate to your development site in SharePoint Online.
18. Click Site Contents in the left-side navigation.
19. Click Add an App.
20. Click From Your Organization in the left-side navigation; you should see your newly added application listed.
21. Click the tile for the application. A pop-up dialog opens, asking whether you trust your app.
22. Click Trust It, as shown in Figure 25. Your new app becomes listed in the site contents.
23. Click it. You are redirected to your app and should see the title of your site written to the page, as shown in Figure 26. Note that the URL of your app pages sits in
o365apps.net.
This is the SharePoint Online–controlled Azure tenancy that your code
package was automatically deployed to during installation.
How It Works
In this exercise you created a
rudimentary SharePoint Autohosted app that simply lists the name of the
host site that app is installed in. You packaged the app using the
Visual Studio Publish wizard and then deployed to your app catalog in
SharePoint Online. When you installed the application, SharePoint
Online took the code package from the app package and deployed it to
Azure for you. It then installed the application in your SharePoint
site. Note that in this example you didn’t need to deal with client IDs
and secrets. That is because SharePoint Online creates and configures
those for you in the Autohosted scenario. When the application ran it
used the Client-Side Object Model (CSOM) combined with OAuth to call
back to SharePoint and retrieve the name of the host Web SharePoint
site.