Debugging and Publishing the HTML App in SharePoint
The next step is enabling an application to be hosted on SharePoint 2013 online, a very easy task:
- In Solution Explorer, double-click Properties. When the designer is ready, click the SharePoint tab. A new button called Enable SharePoint will appear, as shown in Figure 3.
- Click the Enable SharePoint button and specify the developer site for debugging. In the Site URL box, enter the address of your developer site (see Figure 4), and then click Validate.
- After you click Validate, Visual Studio LightSwitch asks you to enter credentials to access your Office 365 account. Notice that you have to enter administrator credentials (see Figure 5), so that LightSwitch can upload the app package for debugging.
Figure 3 Enabling SharePoint publishing for a LightSwitch HTML app.
Figure 4 Specifying the URL for the developer site.
Figure 5 Entering and validating Office 365 credentials.
The next phase in this process deals with security. SharePoint online uses its own authentication mechanism based on the Office 365 accounts, so Access Control is disabled in LightSwitch, as you can see by opening the Access Control tab (see Figure 6). You can't make any changes in these settings.
Figure 6 LightSwitch Access Control is disabled.
With this simple sequence of steps, you've enabled your LightSwitch HTML app to run on SharePoint 2013 and Office 365. Before you publish the app to production, however, you need to debug and test it.
Debugging the App
At debugging time, the application will use SharePoint online only for authentication; it will run locally. For this reason, the first time you debug an application for SharePoint, Visual Studio needs to install a certificate for Internet Information Services (IIS) Express, the lightweight edition of IIS that LightSwitch uses for debugging. This action is required because SharePoint apps use Secure Sockets Layer (SSL) connections, and the https://localhost address must be trusted on the development machine.
To debug a LightSwitch HTML app for SharePoint, simply press F5. Visual Studio shows a dialog box containing information for the certificate, as shown in Figure 7.
Figure 7 Summary information about the localhost certificate.
The dialog shows summary information for the certificate and you need to trust it, so click Yes. Visual Studio will ask for your confirmation before installing the certificate (see Figure 8). Simply click Yes at this point.
Figure 8 Installation confirmation for the localhost certificate.
Visual Studio LightSwitch will package the application and upload it to the local IIS server. When the application is ready, your web browser will open with an instance of the debugger attached. The first time (and only the first time) you debug the application, the SharePoint developer site will ask you to trust or reject the application, as demonstrated in Figure 9.
Figure 9 Trusting a new app for SharePoint.
After you trust the app, it will run in your web browser. Figure 10 provides an example.
Figure 10 The sample application running on SharePoint 2013 and Office 365.
Figure 11 Managing apps in testing.
In summary, at debugging time:
- The app has been hosted on your local instance of IIS Express.
- The app uses the SharePoint developer site to provide authentication.
- The LocalDB feature of SQL Server has been used for the intrinsic database.
Of course, the situation changes when you want to publish your application to production; your app and data must be moved to SharePoint online. The next section describes this technique.
Publishing Your LightSwitch App in SharePoint
Publishing your LightSwitch HTML app to SharePoint online is not a difficult task, but it involves some manual steps:
- Change the solution configuration from Debug to Release in the Visual Studio toolbar.
- Select Build > Publish.
- The LightSwitch Publish Application Wizard asks you to specify how the application will be hosted (see Figure 12):
- Autohosted. Select this option when publishing to Office 365. In fact, Office 365 uses Windows Azure automatically to host your application on the cloud, and it uses SQL Azure to host the application database. This is a very convenient option, because it doesn't require any manual configuration.
- Provider-hosted. This option requires you to have your own service to host a SharePoint installation on either a web server or a cloud service. It also requires you to enter all the necessary information to configure deployment. This feature is beyond the scope of the article, so I won't discuss it here.
For this example, select Autohosted.
Figure 12 Hosting options for your app on SharePoint.
Figure 13 Specifying the application package.
Figure 14 Verifying the developer site's address before deployment.
Figure 15 Trusting the application for publication.