Monday, 19 December 2011

How To Apply "Compress Session State"

WHAT IS “SESSION”: “A session is a period of time that a unique user interacts with the web application.”
“Retaining data for a unique user is known as session state.”

LIMITATION IN PREVIOUS VERSIONS: In previous versions of ASP.NET session state data has to be stored outside the web application’s worker process that “Increases the Latency of the Application”.

IMPROVEMENTS IN ASP.NET 4.0: ASP.NET 4.0 introduces compress session state through which the size of session state date can be reduced by 97%.Session-state data can be serialized/deserialize using System.IO.Compression.GZipStream.

WHY MAKE CHANGES: In previous versions of ASP.NET session-state data has to be stored outside the web application’s worker process, so session data must be serialized before sending it to remote storage. When developer wants to store a big amount of information in session state, he would have a quite large serialized data that “Increases the Latency of the Application”.

There are two ways available for managing the session state:
In-Process and Out-of-Process
Out-of-Process has two modes: State Server & SQL Server
ASP.NET 4 introduces a new compression option for both kinds of Out-of-Process session-state providers. 

Note: For managing Session State in stateserver first thing we have to create ASPSTATE DB. Following command must be executed in command prompt: 
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319>aspnet_regsql.exe –S <SQLServer name> -E –ssadd –sstype p
To applying this feature in your application, you have to add below code in web.config under system.web. Remember this CompressEnabled must be “true”

          Now save the pages and enjoy the magic of “Compress Session State”. Check what I
          saw in my application:

Before Enabling Compression in web.config :

After Enabling compression in web.config  :

  • This compression feature enabled user to reduce the time it takes for a web application in responding by reducing the size of session data.
  • This feature is useful for those, who have large session date because this feature reduces the session state data by 97%.

No comments:

Post a Comment