Wednesday, December 7, 2011

Storing Session State in Windows Server AppFabric Cache


Hi,

Today I am going to post about how to make use of Windows Server AppFabric Cache as Session Store for the Asp.Net Web Application.

This can be achieved by following simple steps

    1)  Add the reference of following Assembly from the following location
a.  Microsoft.ApplicationServer.Caching.Core.dll
b.   Microsoft.ApplicationServer.Caching.Client.dll
        
The above 2 assemblies can be located at the following locations –

 %windir%\System32\AppFabric

    2)  Add the following entry at the ConfigSections of the Web.Config

<section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
            Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0,
            Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          allowLocation="true"
          allowDefinition="Everywhere"/>

    3)  Inside the configuration tag, add the following entry
   <dataCacheClient>

      <hosts>
        <host name="a4ml01382" cachePort="22233"/>
      hosts>
      <securityProperties mode="None" protectionLevel="None" />
 
      <transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456"
                         maxBufferSize="8388608" maxOutputDelay="2"  channelInitializationTimeout="60000" receiveTimeout="600000"/>

  dataCacheClient>

    4)  Inside the System.Web tag, add the following entry

 <sessionState mode ="Custom" compressionEnabled="true"customProvider="AppFabricCacheSessionStoreProvider" cookieless="false">
      <providers>
        <add
          name="AppFabricCacheSessionStoreProvider"
          type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider"
          cacheName="AspNetCacheName" />
      providers>
    sessionState>


    5)   You are all set to go from Client Asp.Net Application for making use of AppFabric cache   as Session store.. Now you need to do the following 2 steps to ensure that it works

a)  Ensure that the AppFabric Cache service is running
b)  Ensure that you have created the cache with the name – AspNetCacheName – because this is the place where in the session data is stored( We have explicitly named this ‘AspNetCacheName ‘ in step 4 )


I hope this helps!.

Regards,
-Vinayak

No comments: