Windows Azure is a very popular technology and buzz word and with good reason. Cloud based applications will dramatically change the landscape of hosted applications and IT infrastructure while lowering costs and investment for companies. Kentico quickly recognized this emerging technology and modified their product to allow developers and companies to take advantage of this new hosting space and systems. This blog is a step-by-step process of deploying a Kentico site to Azure. I’ve also added in some tips and tricks I learned along the way to hopefully help you out. Deploying Kentico to Azure is a lengthy process so this blog is rather long as a result.
Much of the details of this blog are covered in Kentico’s deployment guide for Azure which I definitely recommend you read first!
» Kentico CMS Windows Azure Deployment Guide
1. Setting up an Azure account
The first step in deploying a Kentico site to Azure is to set up the right Azure subscription. Microsoft has a varied pricing model for Windows Azure, based on usage, size, and configuration. Be sure to research the different options to make sure you are signing up and paying for the right option for your site and company.
» Windows Azure Pricing
2. Selecting the right site
Before deploying a Kentico site to Azure, you will need to research your applications to select the right one. Not all sites may perform well in Azure. While Kentico does support Windows Azure, there are some limitations
. Initially there were several features not supported within Kentico, however, Kentico worked diligently to resolve them. At this point in time, the only major feature not supported is the ability to run multiple instances within Azure. But as with everything else they do, I am sure Kentico is working toward adding this functionality and we will see it soon.
3. Converting the Kentico site to a web application
After securing a subscription and selecting a site, the next step is to convert the Kentico site to a .NET web application. Windows Azure requires that all sites be a web application due to the way it compiles and stores the DLLs and code. Martin Hejtmanek has detailed this process in this blog.
I found it easiest to start with a fresh installation of Kentico 5.5 R2, if possible. This may require you to upgrade your existing application to 5.5 R2, and then export the site into a fresh installation. The reason for this is that I found older versions of sites (built on 4.1/5.0/etc.) may have certain files which Kentico has since removed from their installations. Starting with a fresh 5.5 R2 installation and importing a site seems to remove many of those issues and simplifies the build process.
4. Configuring the web application for Azure
Before a site can be deployed using the file system in to Azure, you will need to add some references to the application. These references allow you to access the file system to save files and indexes in your site. Under the web application, add references to following:
In addition to these references, you need add the webrole.cs file to the root of your web application. This file configures the storage account for Windows Azure and sets up the appropriate resources when your site is deployed. Kentico has detailed this process in the Azure deployment package
Many labels within a Kentico site are stored in an .resx file. You need to mark these files to compile in order to get label names to display properly. Under /CMSResources, select all the files and choose "BuildAction=Content" and "Copy to Output Directory=Copy Always".
5. Adding and configuring a web role
The next step to deployment is to add a web role to your solution. Web roles determine how the application will be deployed in Azure and how it is accessed. Be sure to select the correct options when configuring your role to match your subscription/usage requirements.
Add a web role example
| Web role options example
If your site is using the file system, you will need to configure your Azure storage account prior to deployment.
- In the Windows Azure Platform Management tool, select “New Storage Account”.
- Create the new storage account and note the “Account Name” and “Primary Access Key” View Example
- In your webrole.cs file, enter these values for the “storageName” and “sharedKey” values View example
After configuring your Azure Storage account and webrole.cs file, add the following “Local Storage” setting to your web role properties.
Local storage example
6. Deploying the database to SQL Azure
At this point I like to deploy my database to SQL Azure to test its functionality locally prior to deploying the application to Windows Azure. SQL Azure databases can be configured to allow access from specific IP addresses/ranges so you should be able to allow your development machine to access it. The SQL Azure Migration Wizard Tool
will convert your database to SQL Azure and copy up all of your data.
SQL Azure Migration Tool example
Be sure to select “Analyze and Migrate / SQL Database.” Any other option seems to fail and will not deploy your database to Azure.
Once you upload your database to SQL Azure, you will need to set your firewall rules in SQL Azure. Be sure to check "Allow other Windows Azure services to access this server". This will allow connectivity from your Windows Azure applications. For development purpose, add another firewall rule with your external IP so you will be able to test from your local machine.
Firewall rules example
After deploying your database to SQL Azure, you should be able to update your connection string on your local application and test connectivity.
<add name="CMSConnectionString" connectionString="Persist Security Info=False;database=[SQL AZURE DATABASE NAME];server=[SQL AZURE DATABASE SERVER NAME].database.windows.net;user id=[SQL AZURE USERNAME];password=[SQL AZURE PASSWORD];Current Language=English;Connection Timeout=240;"/>
7. Running your site locally
Like all other VIsual Studio projects, you can hit F5 and start your Azure application locally. This instantiates the Compute Emulator (which simulates the Azure environment), as well as the Storage Emulator (which simulates Azure storage). These utilities help you see how your application will run in the Azure environment and identify any issues with functionality.
Compute emulator example
| Storage emulator example
If you're using the Azure SDK 1.3, you will encounter an issue when running your application locally. After working with Kenitco and Microsoft, we have determined there is an issue with the hardcoded timeout of the Compute Emulator which will cause it to not start properly due to the number of files within the Kentico application. To get around this issue, you can start the application manually, via the WIndows Azure SDK Command Line Utility.
To start your application via the command line, use the following command:
csrun /run:C:\inetpub\wwwroot\[SITE NAME]\bin\Release\[SERVICE NAME].csx;C:\inetpub\wwwroot\[SITE NAME]\bin\Release\ServiceConfiguration.cscfg /launchbrowser
Cloud command example
Running the application locally against your local database will be much more responsive than connecting to the SQL Azure version. I usually only run the application locally to confirm that it builds properly. In the event you need to run it locally, I would recommend you set the web application as your start-up project to avoid the Compute Emulator issue.
8. Deploying the role to Azure (staging)
After testing your application against the SQL Database, it’s time to deploy! Follow the wizard in the Windows Azure Platform Management Tool to create a new hosted service and deploy your application. Take care in naming your service/URL prefix. These will be live URL’s once the site is published.
Staging deployment example
When naming your deployments/URLs try to adhere to a naming convention for your company/organization.
These are not necessarily how users will access your site, however, they are live URLs and will make sure all of your deployments have a consistent name and configuration.
Once your application is successfully deployed, test its functionality using the "GUID-based" URL for the deployment.
Staging URL example
In order to run your site on the "GUID-based" URL, you will need to a create a Kentico license. Be sure your Kentico license supports this prior to deploying to Azure. If it does not, contact Kentico support to obtain a temporary license for your application.
9. Deploying the role to production
Once you have tested your application you can deploy it to your production deployment. If you haven’t created the production deployment yet, follow the same steps for the staging deployment but select “Deploy to production environment”.
Production deployment example
If you have already created your production deployment, you can select the “Swap VIP” button in the Windows Azure Platform Management tool. This option will swap your staging and production environments in about a minute! This will allow you to “stage” a deployment change/site and choose when you want to deploy it. Additionally, it gives you a standby deployment in case you need to revert back to the original if there is a problem. Note that each deployment (both staging and production) have separate charges and staging deployments accrue costs as well.
10. Final steps
After deploying a production deployment and testing, you are ready to finalize your Azure application. In Azure, each application's assigned a unique IP and URL. Microsoft recommends you set up a CNAME for the “URL” you entered for the deployment using your company’s URL. In my opinion this is excessive because it will require a double DNS lookup for every site request. Each Azure application does get an IP which at this time Microsoft is saying should
stay with the deployment. Hopefully they find a way to secure them to a subscription so CNAMEs can be avoided.
Change your DNS to point to your new IP (or set up a CNAME To the URL you entered for the deployment) and you should be good to go!
Be careful when deleting a deployment. Any IPs assigned to that deployment may be allocated to a different company if a deployment is deleted. If you need to remove a site/deployment but want to retain your IP, just stop the deployment to keep from losing your IP!
I hope this guide helps you develop your Kentico site for Windows Azure. It’s a long process, but Kentico has done a fantastic
job at documenting the process and assisting me with my deployments. Dominik Pinter helped tremendously and together we worked through all of the issues. Good luck and definitely let me know if you need any help!