21.Jun.16

Milan Nankov

Milan Nankov

There are various ways to deploy Sitefinity to Azure depending on your needs – you can create a virtual machine where you have total control over the infrastructure that Sitefinity is running on, you can deploy to a Cloud Service where you still have a lot of control but Azure takes care of many things for you like OS updates, the third option is to use Web Apps where Azure handles almost everything for you and you can use features like App Insights out of the box.

Since Sitefinity is a web app Azure Web Apps is a perfect fit for many Sitefinity projects. With Web Apps you get near-instant deployment as compared to Cloud Service where this takes considerable more time. Also, you can easily scale up or down your machines without the need of redeploys. You can easily configure multiple deployment environments – for example, production and staging. You get automatic OS management, the ability to deploy code using GIT, FTP, or Web Deploy. The list goes on and on. If you would like to have friction free hosting and management of your Sitefinity site Azure Web Apps is a great choice. Our website www.newventuresoftware.com runs on Sitefinity hosted in an Azure Web App. For more in-depth comparison between Web Apps, Azure VMs, and Cloud Services you can check out this article.

Having established that Sitefinity and Azure Web Apps are amazingly perfect fit, let's take a high-level view on how we can actually deploy an existing Sitefinity project on Azure. These are the basic steps that need to be carried out:

  1. Create Windows Azure Infrastructure
  2. Migrate Database
  3. Setup Sitefinity to Use Azure SQL Database
  4. Deploy to Azure

In the first one we will create the needed Azure infrastructure to host our Sitefinity web app – we will create a Web App and a SQL Server to host the database. The second step will make sure that our database is in a format that is supported by the cloud version of SQL Server (more information on that later). After that we will configure Sitefinity to use the cloud database and make sure that the migration is a success. The final step is to actually upload our web app in the cloud and do some final configurations that will make our app a bit more secure.

Let's start

Step 1 - Create Windows Azure Infrastructure

We basically need two things to have our Sitefinity running in Azure – create Azure Web App and SQL Server. I am assuming that you already have access to Azure and you are authorized to create and configure Azure resources. If you are new to Azure you can check out the getting started page.

Create Resource Group

The first step is to create a resource group. Resource groups allow us to group various Azure resources like VMs, DBs, Web Apps, etc. For example, on our Azure account, we have defined a resource group called NVS-Website that host all resources related to www.newventuresoftware.com. This makes it really easy to find and manage resources.

To create a resource group, open the Resource Groups tab on the left and then click Add. Add Resource Group

On this screen you will be able to choose a name for the resource group, the subscription it is linked to, and its location. The Resource group location setting is a handy one since it dictates the default physical location for resources you add to the resource group.
Create Resource Group

Once you are ready click Create at the bottom of the page. Your resource groups should look very similar to this:
Created Resource Group

Now that we have a resource group, let's create a Web App that will host our Sitefinity app.

Create Azure Web App

Add Resource To Resource Group

Click Add on the command bar of the resource group. Search for Web App on the next screen, select it, and choose Create.
Create Web App

Here you can choose the name of the Web App, the Azure subscription, the resource group, and an App Service plan. The resource group and the subscription will be set automatically. You will have to create a new App Service plan if you haven't done this before. Choosing a plan is important since the plan defines the available resources (traffic, ram, etc.) of your web app and also shapes the bill at the end of the month. Fortunately changing the plan is very so there is no need to decide on the right plan for you at this very moment. Choose S1 Standard plan for now. You can take a look at the different plans here.

Once you are done filling the required information, click Create to create the Web App. Azure will probably need some time to prepare everything – you will be notified once your app is ready.

While waiting for our app to be prepared we can create a SQL Server.

Create Azure SQL Server

Since the Sitefinity DB will also live in the cloud, we need a SQL Server that will host the database. Navigate to the resource group and click Add. This time, search for "SQL Server". From the list of results choose SQL Server Logical and click Create.

Add SQL Server

On the next page, there are some SQL settings to be configured.

Create SQL Server

Here the settings are pretty straightforward – choose a suitable name for the server and then username and password of the server administrator account. We will later use this account to perform various administration tasks when migrating the original Sitefinity database.

We will not be creating a database at this point since it will be created for us at the end of the DB migration process.

Once the Web App and the SQL Server are ready, the resource group should look like this:
Resource Group with Web App

Step 2 - Migrate Database

The version of SQL Server that runs in Azure is not 100% identical to the one that run on premise. There are features like "EXECUTE AS logins" which are not supported. For that reason we have to first make sure that our DB is compatible with Azure, make changes to our DB if necessary, and only after that we can move our data to Azure. The differences between Microsoft SQL Server and Azure SQL Database are discussed at length in Azure SQL Database Transact-SQL differences.

There are various paths to take when migrating an SQL Server database to the cloud. A very good article on the topic is SQL Server database migration to SQL Database in the cloud which discusses the different approaches. The way that worked well for us is using Microsoft® SQL Server 2016 Upgrade Advisor (hat tip to my colleague Vladimir Milev). This is a tool that automates the whole process of migrating a database and we will be using it to carry out the migration.

Step 2.1: Install Microsoft SQL Server 2016 Upgrade Advisor

The tool can be obtained from here. The tool is not large so you should be able to download and install it in no time.

Step 2.2: Backup Database

There is always a chance that such migrations can fail. Make a backup of your Sitefinity database before continuing.

Step 2.3: Migrate Database

Open Microsoft SQL Server 2016 Upgrade Advisor and click Migrate to Azure SQL Database on the top left. Once you do that you will be presented with options to connect to the SQL Server instance that hosts your current on-prem Sitefinity database. Enter the credentials, connect to the database and choose the database that should be migrated.

Migrate Sitefinity Database

Once you do that the tool will start converting your DB to a format supported by Azure.

The process could take a while for large databases. Once ready, you will be presented with a screen where you will be able to inspect any issues, if any, that the tool has discovered. In case you are working with a standard Sitefinity database there should be no issues whatsoever.

The next step is to deploy our migrated DB to Azure. Luckily Upgrade Advisor will help us with this task as well.

Deploy Database To Azure

To finish the migration process, select the database on the left and click on Select Target. This will open a new page on the right where that allows us to choose a server where the migrated DB will be deployed. For this step we need the settings that we used to create our SQL Server. Enter the name of the server and the credentials of the admin user then click Connect. If the connection settings are okay you will be able to confirm that this is the correct SQL Server by clicking Select. At this point the button Migrate should light up. Press that button and in a few moments your database will be deployed to Azure.

If you go back to the resource group in Azure Portal you should see one additional item there. This is the migrated database that Microsoft SQL Server 2016 Upgrade Advisor has created for us.

Resource Group With Database

At this point our Database is ready and we are half way thought the migration process. This is a good place to verify that the DB migration has been successful. The best way to that is to actually start using our cloud database.

Step 3 - Setup Sitefinity to Use Azure SQL Database

The first task is to move the database connection string to the web.config file. The process is demonstrated in this article.  Skip this step if you are already using web.config to store connections strings.

Now we need to update the connection string so that Sitefinity is using our cloud database. We can easily obtain the connection string to the cloud DB using the portal – just navigate to the resource group and select the SQL Database listed there.
Getting connection string

Click on "Show database connection strings" and copy the first connection string (ADO.NET). The connection string will look something like this:

Server=myazureserver.database.windows.net;User ID={your_username};Password={your_password};Database=migratedDatabaseName; Trusted_Connection=False;Encrypt=True;

At the moment it is missing the actual username and password. Replace the username and password placeholders with the actual ones – these are the same setting that were used when creating the SQL server. In addition to that, we need to add "Backend=azure " to the connection string. The final connection string should look something like this.

Server=sitefinityonazure.database.windows.net;User ID=dbUser Password;dbUserPassword;Database=migratedDatabaseName; Trusted_Connection=False;Encrypt=True;Backend=azure

Once ready, comment the current connection string and the new on to web.config. Run your Sitefinity project to make sure that everything works as expected. At this point, we have a Sitefinity project using a cloud database. If everything is okay, we can continue with deploying our Sitefinity project to the cloud.

Step 4 - Deploy To Azure

For this one we need Visual Studio. Open Visual Studio and load your Sitefinity project.

One very important thing to do is to make sure that all Sitefinity configuration files are included in the project. Otherwise you will end up with some nasty exceptions. To do that, click "Show all files" in Solution Explorer and include the folder App_Data -> Sitefinity -> Configuration.

There are various ways to deploy ASP.NET applications to azure. We are going to use now is the so called Web Deploy since it is very easy to use and configure. Before we can actually deploy anything to Azure, Visual Studio needs credentials in order to copy files to the cloud. There are two ways to get those credentials – one is login in to Azure using Visual Studio, and the other one is to get a file called Publish Profile. This file contains the necessary info do be able to deploy to Azure. We will go with the second approach since it is a bit more fun.

Open the Azure Portal and navigate to the Web App that we have created. There you will find the "Get publish profile" button. Click it to download the publish profile file.
Get Publish profile

Now that we have, let's do some deploying.

Right-click on the Sitefinity project in Visual Studio and choose Publish. A dialog will appear – this is where we configure how our project is deployed. From the various options that are presented choose "Import" and select the file that we have download from the portal.

Import Publish profile
This will automatically configure how the project is deployed to Azure and the only thing left to do is to click Publish on the next screen.

Publish Web App

In a minute or so you should be able to navigate do the URL of your Web App and see your Sitefinity project up and running. Hooray!

Need consulting on this topic?

Yes No