Sunday, May 23, 2010

Difference between Application, Session, ViewState and Cache objects

Session has a Session ID which is created for every user so if the user request the web application, then a session ID will be created for this user and if he/she exits from the web application, the Session ID will be lost and a new one will be created if he/she requests the web application again.

While in Application object once the first user requests the web application, the application object will be created and maintained till the last user exits from the web application

ViewState is a technique used in ASP.NET to keep the values or settings applied to ASP.NET Server controls persistant during round trips between client and server.

You can check the ViewState object in the source code of the page, it's encrypted so users can never watch what is really written in there.

It's really recommended to disable unused ViewStates on some of ASP.NET Server controls like Labels by going to any server control and set the EnableViewState property to false

Cache is a technique used in data that takes long times to be retrieved e.g. data that has not been changed and is retrieved from SQL Server database and with Caching data is going to be retrieved from memory.

Just to let you know, caching an object or a page has three restrictions to trigger the server to disregard getting the data from memory and to enforce retrieving the data from the page, it should be used in certain circumstances to ensure that users will get the latest data.

No comments:

Post a Comment