SIGN UP MEMBER LOGIN:    
ARTICLE

Using Window Server AppFabric For Caching Your ASP.Net Session

Posted by Amit Choudhary Articles | ASP.NET Programming July 19, 2011
Here I’m going to talk about the caching feature available in the latest version and its use in ASP.Net session management.
Reader Level:


The Window server AppFabric is generally available now and the latest version can be download from here. There is a number of features the Window server AppFabric provides to Monitoring, Hosting and managing the load of your application by providing scalability. But here I'm going to talk about the caching feature available in the latest version and using it in ASP.Net session management.

Why should I use Windows Server AppFabric for Session Management in ASP.Net?


Windows Server AppFabric provides a highly scalable in-memory application cache for all kinds of data. With distributed caching, your application can match increasing demand with increasing throughput by using a cache cluster that automatically manages the complexities of load balancing, scale-out, and failover. With the caching features of AppFabric you get:

  • Scalable in-memory, distributed cache for any serializable data.
  • Seamless integration with ASP.NET.
  • High availability and dynamic scale-out of cluster nodes.
  • Optional local cache with eviction policies.
  • Cache change subscriptions and notifications.

How to use ASP.Net Session provider?


Using the Custom SessionState setting to store the session into the Windows AppFabric Cache.

First add the following assembly reference to your project:
  • Microsoft.ApplicationServer.Caching.Core.dll
  • Microsoft.ApplicationServer.Caching.Client.dll

Now the question is; where to find these assembly files? You can locate these files in the %windir%\System32\AppFabric directory.

Add the following custom sessionstate settings


<sessionState mode ="Custom" compressionEnabled="true"
customProvider
="AppFabricCacheSessionStoreProvider" cookieless="true"
>
<providers>
<!--
specify the named cache for session data -->
<
add
name="AppFabricCacheSessionStoreProvider"
type="Microsoft.ApplicationServer.Caching.
DataCacheSessionStoreProvider
"
cacheName="MySession" />
</providers>
</
sessionState>

Now make sure your Cache service is configured and running properly and you have created the Cache named MySession. To install and configure the Cache Services read this article about Installing and configuring Windows Server AppFabric Cache Services.

You can now start using the session to store your data.

protected void btnGet_Click(object sender, EventArgs e)
{
txtItemValue.Text = (string)Session["Item1"];
}

protected void btnPut_Click(object sender, EventArgs e)
{
Session["Item1"] = txtItemValue.Text;
txtItemValue.Text = "";
}

Note:


Once you move the session state outside of the web server process, all the objects you put in the session need to be serializable.

Use the Serializable attribute on your classes to store the custom objects in Session.

Helpful? Just put your comments down below; I appreciate your inputs.

Login to add your contents and source code to this article
Article Extensions
Contents added by Amit Choudhary on Jul 19, 2011
Update: Additional setting you need to put in the your web.config file

Add dataCacheClient settings in config section of your configuration file

<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"/>

 

Now outside the config section define the dataCacheClient setting

    <dataCacheClient>

    <!-- (optional) specify local cache -->

    <localCache

      isEnabled="false"

      sync="TimeoutBased"

      objectCount="100000"

      ttlValue="300" />

    <!-- cache host(s) losthost for local cache or mention the name of cacheHost -->

    <hosts>

      <host

         name="localhost"

         cachePort="22233" />

    </hosts>

    <!-- Security is disabled, otherwise Grant-CacheAllowedClientAccount cmdlet must be used to authorize appPool Identity or You can disabled the security using Set-CacheClusterSecurity cmdlet set all none. But you need to take down the CacheCluster and change and restart again-->

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

  </dataCacheClient>


share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor