what are the alternatives of SESSION VARIABLES?

25,672

Solution 1

To understand the advantages of not using sessions, you have to understand how sessions work.

In the default setup,

  • sessions are identified by a cookie set in the user's browser and
  • the session data is stored in-memory on the webserver

When the user sends a request to the server, the session cookie is sent along. It contains an identifier which the server uses to locate that particular user's session data.

You can configure ASP.NET to

  • use query parameters instead of cookies to store the session identifier
  • store the session data in a database (having a central data store for session data is particularly important if you have multiple servers serving your site)

Now for the advantages of disabling session state:

  1. ASP.NET makes access to the session data thread-safe by serialising requests. This means that, when session state is enabled, ASP.NET refuses to serve concurrent requests from the same user. This is particularly an issue when the user's browser makes a lot of ajax requests. This problem can be mitigated by marking session state read-only for requests where you don't need to update it.
  2. When the request comes in, ASP.NET has to fetch the session data, and it has to write data back when the request ends. This may not be a big issue if session state is stored in-memory, but if data is stored in a central database, this can cause serious performance problems.

Needless to say, these issues are exacerbated by storing large amounts of data for a large number of users.

For more information see

  1. ASP.NET Session State Overview
  2. Fast, Scalable, and Secure Session State Management for Your Web Applications

(that last article is a bit dated, but still a good read).

Alternatives

  • If you can, avoid session state altogether.
  • If you absolutely must associate data with the user, use the mechanisms of HTTP and make the browser carry the data in a cookie or perhaps a query parameter (this is partly what the whole REST-movement is about).

Hope this helps.

Solution 2

Pros and Cons of Session Variables See Here

Share:
25,672
Bhupendra Shukla
Author by

Bhupendra Shukla

Updated on September 02, 2020

Comments

  • Bhupendra Shukla
    Bhupendra Shukla almost 4 years

    What are the limitations of the session variable in developing large web application. Also what are the best alternatives of the session variables.

    Please provide me the alternatives of SESSION VARIABLES

  • Admin
    Admin almost 11 years
    @saratha Did you type the all words in just 4 min's???? It's very amazing :: lol :p
  • Bhupendra Shukla
    Bhupendra Shukla almost 11 years
    @saritha what about its alternative (session variable)...
  • Josh Anderson
    Josh Anderson almost 11 years
    Session variables and cookies aren't synonymous. Your session is identified by a cookie, so you're right that cookies should be enabled for the default session implementation, but you can do a cookie-less session. In fact, cookies are an alternative to session variables. A really bad one, but still an alternative.
  • Saritha.S.R
    Saritha.S.R almost 11 years
    if you need to pass/store data in a page you can use ViewState as well.
  • Hans Kesting
    Hans Kesting almost 11 years
    That post you linked to (and Saritha apparently copied from) is very old - it talks about classic ASP. But mostly it's still valid.
  • Uwe Keim
    Uwe Keim over 7 years
    The MSDN Magazine link, to the September 2005 issue, is broken. Here is an archive.org version, also they provide a CHM download of the complete September 2005 issue, including your article.