Configuring Azure storage

In some situations, it may be beneficial to store files of an on‑premise website on a Microsoft Azure Blob Storage account rather than on a local disk.

  • For example, if your server has a limited storage capacity and you need to save large amounts of file data. Using Microsoft Azure may be more convenient than upgrading your server, especially if the increased requirements are only temporary.
  • The same applies when running Kentico in Azure Web Apps, where use of blob storage is optional (unlike with Cloud Services).

There are two approaches for connecting an Azure storage to your project:

  • Store only media files on Azure storage (recommended)

    • We recommend that you map only media library folders to the Azure storage. This allows you to store large media files on a shared storage and optionally use an Azure CDN for this data, while avoiding issues related to Smart search and Web analytics functionality.
  • Map the whole file system to Azure storage

    • We do not recommend mapping the whole file system to the Azure storage because of possible problems with Smart search and Web analytics functionality. These features use data that is not suitable for shared file systems.

File name case

Unlike standard Windows file systems, the Microsoft Azure Blob storage is case-sensitive. To ensure consistent behavior, Kentico automatically converts all file and folder names to lower case when processing files on Azure storage.

Configuring Kentico to store only media files on Azure storage

To map media library folders to Azure storage, use the API and the built-in Azure storage provider:

  1. Add the following keys to the appSettings section of your project’s web.config file. Specify the storage account name and primary access key:

    
    
    
     <add key="CMSAzureAccountName" value="StorageAccountName" />
     <add key="CMSAzureSharedKey" value="PrimaryAccessKey" />
    
    
     

    To locate the values of these keys on Microsoft Azure:

    1. Open the Azure Management Portal in a browser and log in.
    2. Click Storage.
    3. Select your storage.
    4. Click Manage access keys on the bottom panel.
      • Use the Storage account name and Primary access key values.

Important

Do NOT set the CMSExternalStorageName key in your web.config (remove the key if it is present). Setting the key’s value to azure maps the project’s entire file system to the Azure storage, which is not recommended. See the Configuring Kentico to map its file system to Azure storage section for more information about this scenario.

  1. Open the Kentico web project in Visual Studio (using the WebSite.sln or WebApp.sln file).
  2. Create a new class in the App_Code folder (or CMSApp_AppCode -> Old_App_Code on web application projects).
  3. Extend the CMSModuleLoader partial class.
  4. Create a new class inside CMSModuleLoader that inherits from CMSLoaderAttribute.
  5. Add the attribute defined by the internal class before the definition of the CMSModuleLoader partial class.
  6. Override the Init method inside the attribute class:
    • Create a new instance of the Azure storage provider.
    • (Optional) Specify the target container using the CustomRootPath property of the provider.
    • (Optional) You can specify whether you want the container to be publicly accessible using the PublicExternalFolderObject property of the provider. True means the container is publicly accessible.
    • Map a directory to the provider. This is the directory that you want to store in the container.



using CMS.IO;
using CMS.Base;

[CustomStorage]
public partial class CMSModuleLoader
{    
    private class CustomStorageAttribute : CMSLoaderAttribute
    {
        /// <summary>
        /// The system executes the Init method of the CMSModuleLoader attributes when the application starts.
        /// </summary>
        public override void Init()
        {
            // Creates a new StorageProvider instance
            AbstractStorageProvider mediaProvider = new StorageProvider("Azure", "CMS.AzureStorage");

            // Specifies the target container
            mediaProvider.CustomRootPath = "mymediacontainer";

            // Makes the container publicly accessible
            mediaProvider.PublicExternalFolderObject = true;

            // Maps a directory to the provider
            StorageHelper.MapStoragePath("~/MySite/Media/", mediaProvider);
        }
    }
}


  1. Save the file. If your project is installed in the web application format, rebuild the solution.

The system now stores files from the ~/MySite/Media/ folder in the mymediacontainer on the Azure storage.

Using Azure storage for multiple projects

It is not recommended to use one shared storage for multiple projects (for example production and testing projects), because the projects would overwrite each others’ files.

However, using the mediaProvider.CustomRootPath property (as described on this page), you can map each project to a different container. This way, each project will have its own section of the Azure storage to store the media files in and no files will be unexpectedly overwritten.

Configuring Kentico to map its file system to Azure storage

Warning: Mapping the Kentico project’s entire file system to Azure storage is only recommended when running on Azure Cloud Services. In other environments, such as Azure Web Apps, this type of setup may introduce issues with Smart search and Web analytics functionality and we recommend that you only map media library folders.

If you do wish to map the entire file system, you can set up additional mappings back to the local file system for the smart search and web analytics folders.

  1. Add the following key into the appSettings section of your project’s web.config file.

    
    
    
     <add key="CMSExternalStorageName" value="azure" />
    
    
     

    This key maps the entire file system of your application to the Azure storage.

  2. Add the following keys to specify the storage account name and primary access key:

    
    
    
     <add key="CMSAzureAccountName" value="StorageAccountName" />
     <add key="CMSAzureSharedKey" value="PrimaryAccessKey" />
    
    
     

    To locate the values of these keys on Windows Azure:

    1. Open the Azure Management Portal in a browser and log in.
    2. Click Storage.
    3. Select your storage.
    4. Click Manage access keys on the bottom panel.
      • Use the Storage account name and Primary access key values.

Additional website settings

When configuring this type of storage, keep in mind that the website itself must be configured to store files in the file system rather than in the database only. In Settings -> System -> Files enable the Store files in file system option.

It is also recommended to enable Redirect files to disk in Settings -> System -> Performance. This means that files will be requested from the Azure Storage account rather than from the database (if possible).

Optional web.config settings for Azure storage

Key

Description

Sample value

CMSAzureTempPath

The system uses the specified folder to store temporary files on a local disk, for example when transferring large files to or from the storage account.




<add key="CMSAzureTempPath" value="C:\AzureTemp" />


CMSAzureCachePath

Specifies a folder on a local disk where files requested from the storage account are cached. This helps minimize the amount of blob storage operations, which saves time and resources.




 <add key="CMSAzureCachePath" value="C:\AzureCache" />


CMSAzureBlobEndPoint

Sets the endpoint used for the connection to the blob service of the specified storage account. If you wish to use the default endpoint, remove the setting completely from the appropriate files.




 <add key="CMSAzureBlobEndPoint" value="http://127.0.0.1:10000/devstoreaccount1" />


CMSAzurePublicContainer

Indicates if the blob container used to store the application’s file system is public. If true, it will be possible to access files directly through the URL of the appropriate blob service, for example:

http://<StorageAccountName>.blob.core.windows.net/cmsroot/corporatesite/media/imagelibrary/logo.png




 <add key="CMSAzurePublicContainer" value="true" />


CMSAzureCDNEndpoint

URL of the HTTP endpoint of a Azure Blob storage CDN.

Note: If you set the CMSAzureCDNEndpoint key, you also need to set the blob storage container to public - <add key=“CMSAzurePublicContainer” value=“true” />.




 <add key="CMSAzureCDNEndpoint" value="kentico123.vo.msecnd.net" />


CMSDownloadBlobTimeout

Specifies the timeout interval in minutes for importing files from Windows Azure Blob storage into Kentico.

The default value is 1.5 minutes. Increase the interval if you encounter problems when importing large (about 2GB) files.




<add key="CMSDownloadBlobTimeout" value="50" />