Windows Azure SQL Database Marketplace
In this blog you will learn how you can take an existing ASP.NET application and publish it to a Windows Azure Web Site. The demo application is an ASP.NET MVC 4 and uses Entity Framework (EF) Code First to access the data stored in SQL Server. It also uses EF Code First migrations to manage the schema of the application.
Web applications created using Visual Studio can easily be published to Windows Azure Web Sites. After you have created your Web Site in the Preview Portal you should download the publish profile. This can be achieved by clicking the Download publish profile link in the quick glance section of the Web Sites dashboard. This is shown in the image below.
You will need to import this publish profile into Visual Studio to enable your application to be published. To do this, on the Web Project right click and select publish.
This will open up the new publish dialog. If this is the first time you are publishing this project then the dialog will be opened on the Profile tab as shown below.
You should now click Import and browse to the publish profile which you downloaded previously from the portal. Once you import this file you will automatically be taken to the Connection tab where you will see the publish configuration values filled in.
On this page you can click the Validate Connection button to ensure that your machine is able to communicate with Windows Azure and that you are ready to proceed to the next step.
After you click Next, on the Settings tab you will see any databases which your application uses. This application contains an EF context, SqlImageContext, which is automatically detected. For each database you can expand the drop down to select the connection string which should be used when the application is published. You can see this in the next image.
When using Code First there are two ways that you can configure your migrations to be executed when the context is first accessed; either in code or in web.config. When you check the “Apply Code First migrations” checkbox your web.config file will be modified during publish to ensure that the Code First migrations are executed when the context is first accessed. Note: this will not modify your original web.config in your project, only the web.config which gets placed on the server. Now we can move on to the final step, preview.
On the preview tab you will get a quick overview of all the file operations which will be performed when you publish your application. You will also see any databases which have been configured for publishing. In the image below you can see the preview tab.
Since this is the first time that you are publishing the application the entire set of contents will be pushed to the server. In subsequent publishes only changes will be published. Now you are ready to publish your application. You should now click the Publish button.
After clicking Publish you can monitor the progress of the publish process in the Output Window. When the publish process successfully completes a browser will be automatically opened to your sites location. This all that you need to know to quickly publish your Web Project to a Windows Azure Web Site. For more details on this process you can take a look at our tutorial Deploying an ASP.NET Web Application to a Windows Azure Web Site and SQL Database.