FÖRSÄLJNING: 1-800-867-1389
EN
Det här innehållet finns inte tillgängligt på ditt språk men här finns den engelska versionen,

How to: Configure the ASP.NET Session State Provider (Azure Shared Caching)

Updated: June 19, 2014

ImportantImportant
Please note the Azure Shared Caching service will be retired on September 1, 2014 and with it the Azure Silverlight-based portal. Once the Shared Caching service is retired, all remaining Shared Cache deployments will be deleted. Microsoft strongly encourages you to migrate at the earliest opportunity all existing Shared caches to either the Managed Cache Service (currently in GA) or to the new Azure Redis Cache (currently in Preview). For migration guidance, including guidance for migrating without making code changes, see Migrate from Shared Caching. For more information about the current Azure Cache offerings, see Azure Cache.

This topic explains how to configure an ASP.NET web application to use Microsoft Azure Shared Caching for session state. The configuration is done by obtaining the cache settings and modifying the web.config file for the target web application.

noteNote
This topic is specific to Shared Caching. Applications that host caching on roles can use the NuGet Package Manager instead. If you are using role-based caching, see Session State Provider for Azure Cache.

To use Shared Caching for session state

  1. First prepare your Visual Studio 2012 project to use Shared Caching. For more information, see How to: Prepare Visual Studio to use Azure Shared Caching.

  2. In the , select your target cache. For more information about how to create a new cache, see How to: Create a Cache (Azure Shared Caching).

  3. Expand the Properties pane. Note the value of cache Service URL. This is the host name for your Microsoft Azure cache. It can also be referred to as the cache endpoint URI.

  4. Also note the value of the authentication token for your cache. Click the View button in the Authentication Token field to view this information. This is an ACS key that secures access to your cache.

  5. Click the View Client Configuration button on the toolbar.

  6. In the pop-up Client Configuration window, note the XML snippets. The additional section element should be placed at the end of any existing section elements within the configSections element in your web.config file.

  7. The dataCacheClients section should be placed within the configuration element.

    noteNote
    Note that this exposes two dataCacheClient configurations: default and SslEndpoint. The SslEndpoint cache client uses SSL for communications. You can choose to use either cache client configuration depending on your security requirements.

  8. If you want to use for session state caching, add the sessionState section within the System.Web element. In your application, add and retrieve items from session state using the HttpContext.Session property. These values will now be stored in your cache.

  9. If you require SSL communication, change the dataCacheClientName attribute from default to SslEndpoint.

Example

The following example web.config file configures session state to use Shared Caching.

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="dataCacheClients"
             type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core"
             allowLocation="true" allowDefinition="Everywhere"/>
  </configSections>
  <appSettings/>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
    <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider" compressionEnabled="false">
      <providers>
        <add name="AppFabricCacheSessionStoreProvider"
             type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider,         Microsoft.Web.DistributedCache"
             cacheName="default" 
             useBlobMode="true" 
             dataCacheClientName=”default”/>
      </providers>
    </sessionState>

    <authentication mode="None"/>

    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>

  <dataCacheClients>
    <dataCacheClient name="default">
      <hosts>
        <host name="your_cache_service_url" cachePort="22233" />
      </hosts>
      <securityProperties mode="Message">
        <messageSecurity
          authorizationInfo="your_cache_authentication_token">
        </messageSecurity>
      </securityProperties>
    </dataCacheClient>

    <dataCacheClient name="SslEndpoint">
      <hosts>
        <host name="your_cache_service_url" cachePort="22243" />
      </hosts>
      <securityProperties mode="Message" sslEnabled="true">
        <messageSecurity
          authorizationInfo="your_cache_authentication_token">
        </messageSecurity>
      </securityProperties>
   </dataCacheClient>
  </dataCacheClients>
</configuration>

See Also

Var detta till hjälp?
(1500 tecken kvar)
Tack för dina kommentarer

Gruppinnehåll

Lägg till
Visa:
© 2014 Microsoft