How To Work With Sessions in ASP.NET

sessions-in-asp-net

HTTP is a stateless protocol, which means every moment when a new request is made by the client for the server, the state information of the previous request is lost.

There are many methods to store and handle state in asp.net and Session object is among those methods. Caching and Application objects are other objects used for same job.

Caching helps in enhancement of the app performance by lowering the consumption of resources in the system.

sessions-in-asp-net

You can store rapidly used data or web pages in order to enhance the performance, output and scalability of the application by reducing the consumption of the resources of the server.

A Session in asp.net is a session of connectivity between the client and the server. It is the Session object that holds data that communicate to a users’ session. It is a server side state management technique used for storing user centric information into memory for future recovery.

Methods of Storing Session Data

There are four methods to store session data

  1. In process
  2. SQL Server
  3. State Server
  4. Custom
  • In process method stores data in the same asp.net process.
  • SQL Server process stores data in the SQLServer database.
  • State Server method stores data in some other system.
  • Custom method allows you to store session data with a custom storage provider.

New Session data compression support

Asp.net 4 has a new feature – session state compression. Developers can leverage this feature in asp.net 4 and updated version to compress session data in order to store out-of-process sessions.

They need to set the compressionEnabled attribute to “true” in the app configuration file. Take an example:

Read:  How To Get Uninterrupted WhatsApp Messaging Service!

code-1

Session state allows developers to store user centric data to the memory and recognize a specific request in unique way. It can be stored as key/value and can be accessed with HttpContect.Session property.

code-2

Professional .Net Developer just shared a blog about Sessions to make you understand about their working in asp.net. If you have any doubt or want to ask anything related to Sessions or asp.net, just comment in below section.

About the author: Dharak Infotech

Admin of Etech Spider and Aegis Soft Sols. Contact on dharakinfotech@gmail.com for Guest Post, Sponsored Posts or Advertisement Solutions.

Related Posts