A day with .Net

My day to day experince in .net

Configure AppFabric Server for Session State using power shell

Posted by vivekcek on December 17, 2012

In this post i am going to tell you about some problems you may experience when using AppFabric server as your caching state provider. Please note that i am using AppFabric 1.0 (WindowsServerAppFabricSetup_x86_6.1/x64). The commands for 1.1 version may be different.

So first of all you must download and install AppFabric 1.0. Refer my old blog.Install Windows Server AppFabric Caching

After successful installation go to Cache Administration Power Shell. Issue the following commands. You must run the power shell in Administrator mode.Also i hope you have only one cache host in your cluster.



The above command shows the status of the cache host.The cache host may be DOWN or UP.If host is DOWN issue the below



Now issue



Now give permission for all client accounts by


Grant-CacheAllowedClientAccount everyone

Do a restart



Disable Security for session State Provider

This step is very important. In this step you will disable security mode in cache server through power shell.Use the below

command for that.


Set-CacheClusterSecurity -ProtectionLevel None -SecurityMode None

Now you need to specify this in your web config file of asp.net application as below.



    <securityProperties mode="None" protectionLevel="None" />

some time you may experience the below error

ErrorCode :SubStatus:The connection was terminated, possibly due to server or network problems or serialized Object size is greater than MaxBufferSize on server. Result of the request is unknown.

To handle this we have to change the configuration in server side and clients web.config.

1. In power shell export the server configuration to a directory by using the below command

Export-CacheClusterConfig -File [yourfilepath] 

2. Open the file using notepad and add the blow tag and save the file.

    <transportProperties maxBufferSize="8388608" />

3. Now stop the cluster.Import the saved config file and restart cluster.

Import-CacheClusterConfig -File [yourfilepath]

4. In the web.config of client add the below.


    <securityProperties mode="None" protectionLevel="None" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456" 
                       maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000" 

The full Cache Server config.

<?xml version="1.0" encoding="utf-8"?>
        <section name="dataCache" type="Microsoft.ApplicationServer.Caching.DataCacheSection, 

Microsoft.ApplicationServer.Caching.Core, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <dataCache size="Small">
            <cache consistency="StrongConsistency" name="default">
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
            <host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
                hostId="1326169401" size="895" leadHost="true" account="MACHINE1\Administrator"
                cacheHostName="AppFabricCachingService" name="Machine1" cachePort="22233" />
            <securityProperties mode="None" protectionLevel="None">
                    <allow users="everyone" />
                    <allow users="IIS_IUSRS" />
                    <allow users="Administrator" />
                    <allow users="NETWORKSERVICE" />
                    <allow users="MACHINE2\Administrator" />

The full web config

<?xml version="1.0"?>

  For more information on how to configure your ASP.NET application, please visit

    <section name="dataCacheClient" 


Version=,Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere"/>
    <localCache isEnabled="true" sync="TimeoutBased" objectCount="1000" ttlValue="600"/>
     <host name="Machine1" cachePort="22233"/>
<securityProperties mode="None" protectionLevel="None" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456" 
                       maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000" 


6E37C9740DD97EDE3D3'   decryptionKey='B32BDECF54ADED4DE7106A42A78B6E1358A9AE9212D512C6'   validation='SHA1'/>
    <sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
        <add name="AppFabricCacheSessionStoreProvider" 

type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="default" sharedId="MvcApplication"/>
        <add assembly="Microsoft.ApplicationServer.Caching.Client, Version=, Culture=neutral, 

        <add assembly="Microsoft.ApplicationServer.Caching.Core, Version=, Culture=neutral, 

    <httpRuntime />
 <customErrors mode="Off"/>
    <modules runAllManagedModulesForAllRequests="true"/>


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s