Windows AppFabric Caching for SessionState Provider ASP.NET

AppFabric

Using Windows Server AppFabric Caching for Asp.NET Session state provider.


In ASP.NET 4 we have following options to choose and use for managing session state,

1. In-Proc

2. SQL Server Mode

3. Custom


We can use custom session state mode to store session state in AppFabric cache.

To use AppFabric cache for session state we need to configure our application's web.config file according to steps mentioned below.

First of all make sure Windows Server AppFabric is installed and running.


Read install and configure windows server AppFabric to know how to install and configure windows server AppFabric.

Now add references to the following assemblies by right clicking on solution explorer and select add reference.

browse to AppFabric directory in windows/system32, select and add reference to both assemblies mentioned below.

Microsoft.ApplicationServer.Caching.Client.dll 
Microsoft.ApplicationServer.Caching.Core.dll

Now open web.config file and add following in configSection


  


Make sure to change your HOSTNAME in code below.


  
  
    
  



Add this code inside system.web element in web.config

Make sure you write the correct cache name, i m using default cache.


  
    
  



Now we can use AppFabric cache to store our session state as we used to do normally.

protected void Page_Load(object sender, EventArgs e)
{
    // Just and example of storing data in session variables

    Session["Test"] = "AppFabricTest";
   
}

protected void btnTest_Click(object sender, EventArgs e)
{
     lblShow.Text = Session["Test"].ToString(); 
}

If you like this post than join us or share

0 comments: