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.

1.

Get-CacheHost

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

2.

Start-CacheHost

Now issue

3.

Start-CacheCluster

Now give permission for all client accounts by

4.

Grant-CacheAllowedClientAccount everyone

Do a restart

5.

Restart-CacheCluster

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.

6.

Set-CacheClusterSecurity -ProtectionLevel None -SecurityMode None

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

7.

<dataCacheClient>
    <hosts>
        ...
    </hosts>

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

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.

<advancedProperties>      
    <transportProperties maxBufferSize="8388608" />
</advancedProperties> 

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

Stop-CacheCluster 
Import-CacheClusterConfig -File [yourfilepath]
Start-CacheCluster

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

<dataCacheClient>
    <hosts>
        ...
    </hosts>

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

The full Cache Server config.

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

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

The full web config

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <configSections>
    <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"/>
  </configSections>
  <dataCacheClient>
    <localCache isEnabled="true" sync="TimeoutBased" objectCount="1000" ttlValue="600"/>
    <hosts>
     <host name="Machine1" cachePort="22233"/>
    </hosts>
<securityProperties mode="None" protectionLevel="None" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456" 
                       maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000" 
                       receiveTimeout="600000"/>
  </dataCacheClient>
  <system.web>
<machineKey 

validationKey='AFD1EF00AB1FDE92459609D9322D97D5B47627B331FC4600248ADD5CBF2454641010B0A12EB87A2E00B39E07575132374B1486A4471E0

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

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

PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, 

PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <httpRuntime />
 <customErrors mode="Off"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s