Deploying existing MVC projects to Azure Web Apps
If you already have a Kentico website hosted on a traditional web server or prepared for deployment, you can decide to move your project to Azure Web Apps.
This scenario assumes that you have a Kentico project installed on a local file system, connected to a standard Microsoft SQL database. To migrate your project to Azure, you need to:
- Create a deployment environment in Azure using Azure Resouce Manager
- Deploy the project’s database to Azure SQL
- Publish the MVC and Kentico administration applications
Before you begin, please read the Pre-deployment checklist section first.
Pre-deployment checklist
The following is a list of issues you may encounter when deploying an existing project to Microsoft Azure. Assess whether they apply and adjust your project as recommended.
- If your project uses manual web farms, the system may contain unnecessary web farm servers in the database. We recommend that you delete the old web farm servers in the administration interface (via the Web farm application) to ensure that a licensing error does not occur. Moreover, we strongly recommend switching to automatic web farms for the deployed project.
- Your database may contain custom database objects that are not supported on Azure SQL. Because of this limitation of the Azure platform, you might not be able to migrate your database to Azure SQL without modifications. You might encounter issues when deploying your database to Azure if you have somehow customized your database (stored procedures, indexes, access to tables) or if you have developed custom modules.
Creating a deployment environment for MVC projects using Azure Resource Manager
Kentico provides an Azure Resource Manager (ARM) template that helps you deploy all Azure services and resources necessary to host your application in Microsoft Azure.
- Open Microsoft’s Azure Quickstart Templates repository and search for Kentico Xperience.
- Open the Kentico Xperience template and click Deploy to Azure at the top of the page.
- Select your Azure subscription, resource group, and resource location.
- Provide the information required to deploy Azure services used to host your MVC site.
- Click Review + create and finish the template deployment.
The Azure Resource Manager deploys the two Web App instances and an Azure SQL server used to host your Kentico project in Azure.
Deploying the project’s database to Azure SQL
You can host your project in Azure Web Apps and keep your database in a standard Microsoft SQL server. However, we recommend that you also move your database to Azure to ensure the best performance:
- Open the Azure SQL server deployed by the template in the Azure portal.
- Click New database and:
- Specify the database name.
- The database name should match the one you specified in the Connection String Database Name setting when deploying the ARM template. If you left the setting empty, you need to manually add database connection strings to the created Web Apps.
- Leave the Select source dropdown set to Blank database.
- Select a pricing tier.
- Set the database collation to the one used by your local database (Latin1_General_CI_AS by default).
- Specify the database name.
- Click OK.
Azure creates a new database under the SQL server. Continue with configuring the SQL server’s firewall rules to allow connections to the server from your local environment:
- Open the SQL Server in the Azure portal.
- Switch to the Firewalls and virtual networks tab.
- Create a new access rule for the IP ranges of your development and administration machines.
Now you can deploy the project’s SQL database to Azure. Please follow the instructions in the SQL Server database migration to SQL Database in the cloud article according to your requirements.
Publishing the MVC and Kentico administration applications to Azure
The last step in the deployment process is to publish the Kentico administration and MVC applications to the prepared Web App instances. This tutorial deploys both applications using the publishing wizard in Visual Studio.
Before you publish
If you wish to precompile the Kentico administration application before or during your deployment process, you need to store the system’s virtual objects in the project’s CMSVirtualFiles folder on the file system (enable deployment mode in Kentico). See Publishing projects from Visual Studio.
The publishing wizard only deploys files referenced in each application’s .csproj file. If your project depends on any files not included in the solution (for example media library folders and files, administration virtual object files, scripts, stylesheets, etc.), you need to add them using Visual Studio. Enable the Show All Files option in the Solution Explorer menu, locate the file, right-click the file and select Include in project.
Publishing the Kentico administration application
Begin by publishing the Kentico administration project:
Open the Kentico administration project’s solution (WebApp.sln) in Visual Studio.
Edit the CMSApp project’s web.config file and make sure that the sessionState mode is set to InProc.
<sessionState mode="InProc" />
Use InProc mode if you plan to use one instance of the Web App service. If you want to scale your web app to more instances, you will need to configure the session state differently. See Storing session state data in an Azure environment.
Right-click the CMSApp project in the Solution Explorer and select Publish….
Select Microsoft Azure App Service and choose Select Existing.
Click Publish.
In the publishing wizard:
- Select your Azure subscription and the Resource group to which you deployed resources using the ARM template.
- Select the Web App created for the administration project.
- Click OK.
Visual Studio downloads the publishing profile and deploys the Kentico administration project.
After the deployment has completed, perform the following configurations:
- Check that the project is correctly connected to the database (the database installation wizard does not appear).
- Add new licenses for both domains in the Licenses application.
- In the Sites application, set Site domain name to the domain of the Kentico adminstration Web App and Presentation Url to the full URL of the MVC Web App.
- If your administration project is precompiled, make sure that deployment mode is enabled. For example, this may be necessary if you do not deploy your local database together with the project. See Deployment mode for virtual objects for details.
Publishing the MVC application
- Open the MVC project’s solution in Visual Studio.
- Right-click the project in the Solution Explorer and select Publish….
- Select Microsoft Azure App Service and choose Select Existing.
- Click Publish.
- In the publishing wizard:
- Select your Azure subscription and the Resource group to which you deployed resources using the ARM template.
- Select the Web App created for the MVC project.
- Click OK.
- Visual Studio downloads the publishing profile and deploys the MVC project.
After the deployment of both applications has finished, perform the following final configurations:
- Make sure your live site and administration Web Apps are configured to use the same server time zone. See Changing the server time zone on Azure Web Apps.
Increasing storage capacity on Azure Web Apps
By default on Azure Web Apps, all files are stored in the file system with the application, including the media files. The capacity of the storage space is limited – the Basic plan has 10 GB storage available, see Websites Limits for details. When you exceed the capacity, for example by uploading large media files, you have the following options:
- Raise the web hosting plan’s pricing tier to Standard, which has 50 GB of storage.
- Configure your system to use Azure Blob Storage and store the media files there.
See Increasing storage capacity on Azure Web Apps for instructions.
Configuring web farms for Azure Web Apps
If you plan to increase the number of instances associated with your Web App service (on the Scale out (App Service plan) tab), you need to configure web farms in your project to dynamically create and delete web farm servers. See Enabling web farms on Azure Web Apps for instructions.