---
title: Storing cache and session state data in Azure environment
related:
  - https://docs.kentico.com/k10/running-kentico-on-microsoft-azure/running-kentico-in-azure-cloud-services/configuring-kentico-azure-projects-for-cloud-services.md
  - https://docs.kentico.com/k10/running-kentico-on-microsoft-azure/running-kentico-in-azure-web-apps/enabling-web-farms-on-azure-web-apps.md
---

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

If you want your Azure Cloud Services or Azure Web App application to use two or more instances (processes dedicated to a Web App or web roles in a Cloud Service), you must configure where the application will store session state information. Session state must be stored either in the database, which is shared among the servers, or in a special service. Session state cannot be stored in the server's memory, because the session would be lost if the web farm switched requests to another instance.

Options for storing session state information in the Azure environment:

- In [Microsoft Azure SQL Database](#storing-session-state-information-in-azure-sql-database) – easy to set up, suitable for small projects or projects with read access to web pages.
- In [Microsoft Azure Redis Cache](#storing-session-state-information-in-azure-redis-cache) – a dedicated cache service appropriate for more demanding projects. See the [Azure Redis Cache Documentation](https://docs.microsoft.com/en-us/azure/redis-cache/).

## Storing session state information in Azure SQL Database

1. Open your Azure project in Visual Studio.
2. Right-click the **CMSApp** project and select **Manage NuGet packages**.
3. Install the **Microsoft.AspNet.Providers** package.
4. Open the **web.config** file.
5. Follow the instructions in the code comments of the **sessionState** section.

After this, your project is configured to store session state information in the Microsoft Azure SQL Database.

## Storing session state information in Azure Redis Cache

> **Info:** **Retired options**
>
> - Azure **AppFabric** caching is retired and its support scheduled to end – see [Microsoft AppFabric 1.1 for Windows Server Support Lifecycle Extension – 4/11/2017](https://blogs.msdn.microsoft.com/appfabric/2015/04/02/microsoft-appfabric-1-1-for-windows-server-ends-support-422016/).
> - **Microsoft Azure Cache Service** was retired in 2016 – see [Azure Managed Cache and In-Role Cache services to be retired on 11/30/2016](https://docs.kentico.com/Azure%20Managed%20Cache%20and%20In-Role%20Cache%20services%20to%20be%20retired%20on%2011/30/2016).
>
> We do not recommend using these services, as their support is going to be ended.

To configure your project to use Azure Redis Cache:

1. Create a new Redis Cache according to the instructions in [How to Use Azure Redis Cache](https://docs.microsoft.com/en-us/azure/redis-cache/cache-dotnet-how-to-use-azure-redis-cache).
2. Open the project in Visual Studio.
3. Right-click the solution and select **Manage NuGet Packages**.
4. Search for and install the **Microsoft.Web.RedisSessionStateProvider** package.

   - This action will automatically add all required assembly references to the project and create the following section in the web.config file:

     ```xml

     <sessionState mode="Custom" customProvider="MySessionStateStore">
       <providers>
         <!--
           <add name="MySessionStateStore" 
             host = "127.0.0.1" [String]
             port = "" [number]
             accessKey = "" [String]
             ssl = "false" [true|false]
             throwOnError = "true" [true|false]
             retryTimeoutInMilliseconds = "0" [number]
             databaseId = "0" [number]
             applicationName = "" [String]
             connectionTimeoutInMilliseconds = "5000" [number]
             operationTimeoutInMilliseconds = "5000" [number]
           />
         -->
         <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="mycache.redis.cache.windows.net"
         accessKey="..." ssl="true" />
       </providers>
     </sessionState>

     ```
   - Specify the **host** name and **accessKey** values which you can find in the properties of the cache service on Azure.
5. Comment out the default session state provider in the web.config file. 
   - By default, it is the InProc provider:

     ```xml

     <!-- <sessionState mode="InProc" customProvider="DefaultSessionProvider">
       <providers>
         <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
       </providers>
     </sessionState> -->

     ```

You can now deploy your project to Azure and start utilizing Azure Redis Cache as a session state provider.
