Tuesday, October 18, 2005

ASP.NET: Cookie VS Session

I wasn't think of it, until my colleague told me that some of the client can't access the site. It's probably due to the browser that rejects from accepting cookies. Both, cookie and Session uses cookie. However, by using cookie, each variables entered by user is stored in client side and with session, only the SessionID is stored in the client PC, which is used by the server to match the variables stored in Server. As you can see, the variables will be stored in server side rather than client pc, which would definately affect the performance of the server(overall).

By using cookie as well, the server application, IIS session state management, can be disable. This will reduce the burden in the server side.

The advantages of using session variable's over cookies is that you can store objects, such as an array, or Dictionary object. Since session variables are stored on the Web server's memory, storing large objects in a user's session on a site with many simultaneous users can lead to reduced memory on the Web server.

So to sum up the use of Application, Session and or Cookie objects for caching in a ASP page:

Use cookies for small non-critical data.
Use Sessions on a user-to-user basis as in an eCommerce site
And use Application variables for site-wide information that doesn't require constant revision.

Reference: 4guysfromrolla

Your Ad Here