Sharing the goodness…
Beth Massi is a Senior Program Manager on the Visual Studio team at Microsoft and a community champion for .NET developers. Learn more about Beth.
More videos »
Note: This information applies to LightSwitch in Visual Studio 2012 ONLY (LightSwitch V2). This post was updated on 6/8/2012 to include changes in RC. For information on deploying LightSwitch applications built with Visual Studio 2010 (LightSwitch V1), please see: Deployment Guide: How to Configure a Web Server to Host LightSwitch Applications
In my last post on deployment I mentioned I’d point out some LightSwitch deployment goodies you get in Visual Studio 2012. There are some really nice improvements and it’s important to point out some of the changes that you see when you deploy your LightSwitch V2 applications to your own web servers. This post will focus on IIS deployment only. Note however that I have the latest Windows Azure SDK for .NET installed. You should install this to get a better Azure publishing experience but it also upgrades the LightSwitch publish wizard which I will be showing in the screenshots below.
For information on Azure deployment enhancements please see: Publishing LightSwitch Apps to Azure with Visual Studio 2012
For the most part, deployment is the same as it was before, albeit with a few nice new features I’ll discuss below. So you can set up your web and SQL servers the same as before. For information on setting up your web servers see:
For IIS7: Deployment Guide: How to Configure a Web Server to Host LightSwitch Applications
For IIS6: Deploying LightSwitch Applications to IIS6 & Automating Deployment Packages
What’s really nice is that you can deploy LightSwitch V2 applications (built with Visual Studio 2012) to any web server you set up using the V1 LightSwitch 2011 Server Runtime prerequisites. However, you no longer need the LightSwitch server prerequisites or any LightSwitch specific tools. The same Web Platform Installer feed used by the rest of Visual Studio web applications will also work for LightSwitch applications which uses Web Deploy 3. This reduces the numbers of steps to provision a server and should make deployment a lot more predictable. Read on to see what else we improved…
The first new feature you will notice on the publishing wizard is the option to publish just the service and not the client. With LightSwitch now supporting OData, a standard web-based protocol for accessing data via services, you can use LightSwitch to easily create smart, secure, middle-tier data services that can be called from a variety of clients. If you choose this option, the LightSwitch client will not be published.
Another new feature you will notice on the publishing wizard is a button which allows you to import a .PublishSettings file to configure the deployment. Webmatrix and Web Application projects in Visual Studio also have this feature. Azure Web Sites and some ISPs/hosters will give you this file to make it easy to deploy to their systems. For more information on creating these files yourself see: IIS.NET: Generate a Profile XML File.
Next is the option to set up security settings. Note the set of tabs you now get to specify all the security options in one place. The second tab is new and allows you to set up HTTPS. By default, communication between the client and the server uses the HTTP protocol instead of the HTTPS protocol, which is more secure. Secure Sockets Layer (SSL) encryption helps to protect confidential or personal information that’s sent between a client application and a server. We recommend that you configure SSL for any site that hosts an application that’s based on LightSwitch so that data on the wire is encrypted. For more information, see Configuring Secure Sockets Layer in IIS 7.
Another new feature is the ability to choose whether you want to publish the database schema when you do a direct deployment (on the Publish Output step you select “Remotely publish to server now”). When you configure your database connections you will now see a checkbox that indicates whether LightSwitch should attempt to update the schema too. So if you are updating your application but you didn’t make any schema changes in the data designer, then you can uncheck this box to speed up the deployment. However, be careful – if you are unsure leave this box checked.
Additionally, if you are generating a package on disk (on the Publish Output step you select “Generate a package on disk”) you can also choose whether you want to generate the SQL database script as part of the package. Also if you are using any external data sources then additional tab will allow you to configure the external connection strings.
When you choose to create a deployment package on disk instead of direct deployment, a package .ZIP file is created for you that you can import into IIS. In IIS7 you can import this package using IIS Manager, right-clicking on the Default Web Site and then selecting Deploy –> Import Application as detailed in the deployment guide. This process will prompt you for all the required parameters to install the package and set up the database. However in IIS6 you need to use the command line to import these, as I showed in my last deployment post.
In LightSwitch V2 there are now also a set of files that you can use to automate the importing of the package and specifying parameters via the command line. These are starting points and should be modified as necessary depending on your settings. Administrators can use these to get the right settings together quickly instead of having to manually create these files.
If you open up the readme it will detail the prerequisites and how to use the batch file. It is similar to the settings I detailed in the previous deployment post (which only dealt with V1 applications). Here are the V2 specific settings in the .SetParameters.xml. (Note that there is a Beta bug where you will see three additional internal parameters, “dbFullSql_Path”, “Update web.config connection string”, and “LightSwitchApplication_Path” so you will need to remove these lines if you see them).
Modify the following settings in bold to your specific values:
<?xml version="1.0" encoding="utf-8"?>
value="Data Source=servername\SQLEXPRESS;Initial Catalog=Application1;
User ID=admin;Password=adminPassword" />
<setParameter name="DatabaseServer" value="servername\SQLEXPRESS" />
<setParameter name="DatabaseName" value="Application1" />
<setParameter name="DatabaseUserName" value="dbuser" />
<setParameter name="DatabaseUserPassword" value="dbpassword" />
<setParameter name="Application1_IisWebApplication" value="Default Web Site/Application1" />
Note that the DatabaseAdministratorConnectionString is only used to create/update the database. The DatabaseUserName and DatabaseUserPassword values are used to construct the connection string in the web.config and is the credential used by the LightSwitch middle-tier when your app is running.
If your application is using Windows authentication you will need to specify one additional parameter:
<setParameter name="Application Administrator User Name" value="DOMAIN\UserName" />
If your application is using Forms authentication you will need to specify three additional parameters:
<setParameter name="Application Administrator User Name" value="UserName" />
<setParameter name="Application Administrator Full Name" value="Full Name" />
<setParameter name="Application Administrator Password" value="strongPassword" />
Once you configure the .SetParameters.xml file, copy the .zip, .cmd and .xml files to the web server where you are the administrator and run the .Deploy.cmd. To install the package and the database run:
See the readme for details on more options.
In LightSwitch V1 when you select to use either Forms or Windows authentication, the deployment wizard would ask for the credentials of the System Administrator that should be in the database initially and then after it deployed the database it would call Microsoft.LightSwitch.SecurityAdmin.exe (which is installed with the runtime prerequisites) to insert the corresponding records into the database at that time.
Now the System Administrator credentials you enter in the wizard are stamped in web.config. So now when your application starts the first time, LightSwitch looks to see if that user exists in the database and if it doesn’t, it will be created. This strategy works even when the LightSwitch runtime prerequisites are not installed. So now if you ever need to “reset” the admin password, you can modify web.config – either directly or via re-publish. If you look in the published web.config you will see these new keys:
<!-- If no admin user exists, create an admin user with this user name -->
<add key="Microsoft.LightSwitch.Admin.UserName" value="UserName" />
<!-- When creating an admin user with Forms auth, use this as the full name -->
<add key="Microsoft.LightSwitch.Admin.FullName" value="Full Name" />
<!-- When creating an admin user with Forms auth, use this as the pasword -->
<add key="Microsoft.LightSwitch.Admin.Password" value="strongPassword" />
Once your application runs for the first time and the System Administrator is added, you can remove these settings to avoid storing the password in your web.config indefinitely.
Most of these are the more advanced IIS deployment settings that should help IT administrators with hosting/deploying LightSwitch applications. And it’s definitely nice that you can host V2 applications without changing your V1 servers. Most users will not need to wade through these settings and will instead deploy directly, hand off a package to an administrator to install, or use the user interface in IIS Manager to import the package manually. However, if you want the power of automated install of packages, and more control over your deployments then these new features should help.
Really like the new deployment options! As a consultant working offsite for a client (and no VPN), I have spent hours working out the quirks of packaging the app and deploying it via RDP. The app uses an external SQL Server database for everything (intrinsic db is not used), which presented additional challenges because the package file included an unwanted SQL script. The V2 changes should make my life easier.
Keep up the great work.
Looks good! Are we now able to deploy a IIS application and rely on integrated authentication for SQL Connection out of the box? I could never get that working with LightSwitch V1
@Trond - Because LS will deploy your web app into the Default Web Site by default, it will use the ASPNET identity when running middle-tier code. So that means by default to use integrated security to your database you'd have to add that user. Instead I recommend creating another app pool that runs under an identity you choose yourself and set that as as user in the database. I show how to do that in my deployment guide in the section "Configuring Application Pools & Security Considerations": blogs.msdn.com/.../deployment-guide-how-to-configure-a-web-server-to-host-lightswitch-applications.aspx
We had an issue creating the Application Administrator. Found out that we needed to have MSDTC set to allow remote clients on IIS. Now all's well! Thanks so much for the instructions. They were invaluable!
Hi, How do i deploy a web application with VS 2012 because it sends an error with the web config maybe something is missing. I ran VS2010 applications without problems.
After installing the Windows Azure SDK for .NET 1.7 (www.microsoft.com/.../details.aspx), more specifically portion of it for the Windows Azure Tools for LightSwitch for Visual Studio 2012, I can no longer Publish a LightSwitch application (non-Azure) to an IIS 6 server. I receive the following message:
Web deployment task failed.
An error occurred when the request was processed on the remote computer.
This provider requires that you use IIS 7.0 or higher on the source and destination servers.
Is there a way to have this installed and still be able to target II6 for non-Azure LightSwitch applications?
First of all, I'm a big fan of you and your blog. I'd learn a lot, and I Thank you so much.
I have a problem deploying a web application using Forms Authentication on VSLS 2012 Professional. Iit is a project Migrated from VSLS 2010
The publishing wizard does not update the security tables of the DB with the admin user, instead it publish the user in plain text into the web.config file.
You said that: "Once your application runs for the first time and the System Administrator is added, you can remove these settings to avoid storing the password in your web.config indefinitely."
But I cant run the aplication due the fact that I cant Login into the applicattion.
Can you help me please?
@Gabriel -- Hmm, I'm not sure what's happening, it may be something related to the upgrade. Please post your question in the forum, there are folks from the deployment team there that should be able to help. If you post a link to your question back here, I'll make sure to have a look.
Thanks a lot. Here is the link to the question:
Hello Beth. I a big fan of yours.
I get the following error while publishing a light switch application to a remote server.
Can you help me with it
An exception occurred when deploying the database for the application.
Failed to import target model DB_9AB61B_CourseManager. Detailed message Cannot open database "DB_9AB61B_CourseManager" requested by the login. The login failed.
Login failed for user 'DB_9AB61B_CourseManager_admin'. C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v2.0\Publish\v1.0\Microsoft.LightSwitch.Publish.targets 1148 10 CourseManager
hi Beth ,
It was a great article you have there. I went throught the article and did a step by step deployment. It worked like a charm on the test environment which lies on our test environment. But when I deployed it on the live envirornment I am getting the below error message.
Load operation failed for query 'GetAuthenticationInfo'. [HttpWebRequest_WebException_RemoteServer]
I folllowed a lot of external blogs with different solutions but couldnt succeed. When i post the link with a
default.htm?IsLaunchedByVS=True&AuthenticationType=None at the end I can view the site online but the page gives me another error as below
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem.
Could you please help me on this.
@hisham - you'll need to turn tracing on to get the stack trace. That will help you diagnose. blogs.msdn.com/.../diagnosing-problems-in-a-deployed-lightswitch-application-eric-erhardt.aspx
You also probably want to ask in the forums, a lot of people there can help.
When I develop and try to publish my desktop silverlight app I get this error below. I have an error coming from a silverlight deployment process. I have tried many things to go around it but failed to locate what is causing it.
The application runs very well in debug mode. But error comes during publishing the application...with access control..:
'An exception occurred when deploying the database for the application.
Could not deploy package.'
Please advise on this.
I am unable to deploy directly to a server because we require smart cards for authentication and don't have username/passwords. The deploy tool requires username and password. I hope that this method is added soon. Thanks.