Setting up Kentico in Azure Web Apps

The following scenarios describe how to create a new Kentico website as an Azure Web Apps service. You have the following options:

On this page

Deploying MVC projects using Azure Resource Manager and Visual Studio

Kentico provides an Azure Resource Manager (ARM) template that helps you deploy all Azure services and resources necessary to host you application in Microsoft Azure.

  1. Open Microsoft's Azure Quickstart Templates repository and search for Kentico MVC.
  2. Open the Kentico MVC environment template and click Deploy to Azure at the top of the page.
  3. Under basics, select your Azure subscription, resource group, and resource location.
  4. Under settings, provide the information required to deploy Azure services used to host your Kentico MVC site.
  5. Agree with the displayed terms and conditions and click Purchase.

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:

  1. Open the Azure SQL server deployed by the template in the Azure portal.
  2. Click New database and:
    1. 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.
    2. Leave the Select source drop-down set to Blank database.
    3. Select a pricing tier.
    4. Set the database collation to the one used by your local database (Latin1_General_CI_AS by default).
  3. 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:

  1. Open the SQL server in the Azure portal.
  2. Switch to the Firewalls and virtual networks tab.
  3. 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 Kentico administration and MVC 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.

Files excluded from projects

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 or files, script files, stylesheets, etc.), you need to add them using Visual Studio. 

To add files to a project, enable the Show All Files option in the Solution Explorer menu, locate the file, right-click the file and select Include in project

Begin by publishing the Kentico administration project:

  1. Open the Kentico administration project's solution (WebApp.sln) in Visual Studio.
  2. 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 each Web App. However, if you need to scale out to more instances, you will need to configure the session state differently. See Storing session state data in an Azure environment.

  3. Right-click the CMSApp project in the Solution Explorer and select Publish....
  4. Select Microsoft Azure App Service and choose Select Existing.
  5. Click Publish.
  6. In the publishing wizard:
    1. Select your Azure subscription and the Resource group to which you deployed resources using the ARM template.
    2. Select the Web App created for the administration project.
    3. Click OK.
  7. Visual Studio downloads the publishing profile and deploys the Kentico administration project.

After the deployment has completed, perform the following configurations:

  1. Check that the project is correctly connected to the database (the database installation wizard does not appear).
  2. Add a new licenses for both domains in the Licenses application.
  3. 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.

Now publish the MVC application following a similar process:

  1. Open the MVC project's solution in Visual Studio.
  2. Right-click the project in the Solution Explorer and select Publish....
  3. Select Microsoft Azure App Service and choose Select Existing.
  4. Click Publish.
  5. In the publishing wizard:
    1. Select your Azure subscription and the Resource group to which you deployed resources using the ARM template.
    2. Select the Web App created for the MVC project.
    3. Click OK.
  6. Visual Studio downloads the publishing profile and deploys the MVC project.

After the deployment of both applications has finished, perform the following final configurations:

Deploying Kentico projects from Visual Studio

This scenario presumes that you already have a Kentico project installed on a local computer and you want to deploy it to an Azure Web App service using Visual Studio. You can also create the Web App service directly from Visual Studio.

Deploying MVC sites

For sites created using the MVC development model, you need to perform the deployment process for both the MVC live site project and the Kentico administration project (using a separate Web App service for each project). However, the database is shared – only create the database once and then use the same connection string in both projects.

  1. Open your project in Visual Studio.
  2. Open the Server Explorer.
  3. Expand the Azure section, right-click App Service, and select Create New App Service...
    • The Create App Service dialog opens.
  4. Enter the web app name (the resulting URL of your application).
  5. Select the Azure subscription under which the Web App will be created.
  6. Select an existing Resource Group or create a new one.
  7. Select an existing Hosting plan or create a new one.

    For MVC sites, we strongly recommend using two different hosting plans – one for the MVC live site application and another for the Kentico administration application. This allows you to scale the applications independently. In most cases, the MVC live site will receive the bulk of the traffic and have different performance requirements than the administration interface.

    Creating an App Service in Visual Studio 2017

  8. Click Create a new SQL Database and create a new database for the application.
    1. Enter the name of the database.
    2. Select an existing or create a new SQL server.
    3. Provide administrator credentials for the server.
    4. Set the Connection String Name field to CMSConnectionString.
    5. Click OK.
      Creating a new SQL Database
  9. Back in the main dialog window, click Create.

Visual Studio creates the App Service. Continue by adjusting your project's web.config file:

  1. Right-click the created web app (you might need to refresh the App Service section for the app to appear) and select View settings.
  2. Copy the connection string value and paste it to the web.config file of your project.

    <connectionStrings>
        <add name="CMSConnectionString" connectionString="Data Source=tcp:YourServerName.database.windows.net,1433;Initial Catalog=YourDatabaseName;User Id=YourUsername@YourServerName;Password=YourPassword;" />
    </connectionStrings>

    Replace YourServerNameYourDatabaseNameYourUsername and YourPassword with your own values.

    Configuring the connection string after deployment

    You can also configure the connection string through the Azure Management Portal in App Services -> select a web app -> Application settings -> Connection strings section. To set the connection string for the web app, change the defaultConnection name to CMSConnectionString.

  3. Make sure that the sessionState mode is set to InProc in the web.config file.

    <sessionState mode="InProc" />

    Use InProc mode if you plan to use only one instance of the Web App service. If you want to scale your web app to more instances, you need to configure the session state differently. See Storing session state data in an Azure environment.

You are now ready to deploy the project:

  1. Right-click the project in the Solution Explorer and select Publish (or Publish Web App).
    • Publish dialog opens.
  2. Click Microsoft Azure App Service.
  3. Select the created web app located under the resource group you specified.
  4. Click OK.
  5. Do not modify the default settings.
    Publishing the Web App
  6. Click Publish.
  7. Once the publishing process is finished, Visual Studio automatically opens the base URL of your project in your default browser. Follow the on screen wizard to complete the database installation.

Once everything is set up, we recommend you perform the following configuration:


Was this page helpful?