---
title: Configuring Azure storage
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

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](#configuring-kentico-to-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](#configuring-kentico-to-map-its-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.

> **Note:** **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](https://docs.kentico.com/k81/managing-website-content/working-with-files/media-library-files.md) 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:

   ```html

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

   ```

   > **Info:** To locate the values of these keys on Microsoft Azure:
   >
   > 1. Open the [Azure Management Portal](https://manage.windowsazure.com) 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.

> **Note:** **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](#configuring-kentico-to-map-its-file-system-to-azure-storage) section for more information about this scenario.

2. Open the Kentico web project in Visual Studio (using the **WebSite.sln** or **WebApp.sln** file).
3. Create a new class in the **App\_Code** folder (or **CMSApp\_AppCode -> Old\_App\_Code** on web application projects).
4. Extend the **CMSModuleLoader** [partial class](http://msdn.microsoft.com/en-us/library/wa80x488%28v=vs.80%29.aspx).
5. Create a new class inside _CMSModuleLoader_ that inherits from **CMSLoaderAttribute**.
6. Add the attribute defined by the internal class before the definition of the _CMSModuleLoader_ partial class.
7. 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.

```csharp

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);
        }
    }
}

```

8. 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.

> **Info:** **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.

> **Warning:** **Media library limitations**
>
> Note that storing a large number of media files in a single folder can significantly affect the performance of your project when editing the files in the Media library application. See [Media library limitations when storing files in an external storage](https://docs.kentico.com/k81/managing-website-content/configuring-the-environment-for-content-editors/configuring-media-libraries.md#media-library-limitations-when-storing-files-in-an-external-storage) for details.

## Configuring Kentico to map its file system to Azure storage

> **Note:** **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](https://docs.kentico.com/k81/configuring-kentico/setting-up-search-on-your-website.md) and [Web analytics](https://docs.kentico.com/k81/on-line-marketing-features/web-analytics.md) functionality and we recommend that you only [map media library folders](#configuring-kentico-to-store-only-media-files-on-azure-storage).
>
> 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.

   ```html

   <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:

   ```html

   <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](https://manage.windowsazure.com) 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.

> **Info:** **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:<br>_**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.<br>**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 Azure Blob storage into Kentico.<br>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" />
 `                                     |
