ASP.NET - Difference between Application object and session object in asp.net

Asked By RAMAKRISHNA T on 30-Dec-11 07:26 AM
what is the Difference between Application object and session object in asp.net?
Suchit shah replied to RAMAKRISHNA T on 30-Dec-11 07:30 AM

application variables are stored at application level and also can be accessed at application-level.

but static varaiables are session-oriented and also can be access at session-level

Refer : http://www.dotnetheaven.com/UploadFile/mahesh/ApplicationState05102005051501AM/ApplicationState.aspx

http://msdn.microsoft.com/en-us/library/75x4ha6s.aspx

ASP.NET includes application state primarily for compatibility with classic ASP so that it is easier to migrate existing applications to ASP.NET. It is recommended that you store data in static members of the application class instead of in the Application object. This increases performance because you can access a static variable faster than you can access an item in the Application dictionary.

The paragraph above is quoted from: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607.

Suchit shah replied to RAMAKRISHNA T on 30-Dec-11 07:31 AM
Session variables are used to store user specific information where as in application variables we can't store user specific information.

Default lifetime of the session variable is 20 mins and based on the requirement we can change it.

Application variables are accessible till the application ends.
sessions allows information to be stored in one page and accessed in another,and it supports any type of object,including your own custom data types.

Application state allows you to store global objects that can be accessed by any client.

The coomon thing b/w session and application is both support the same type of objects,retain information on the server, and uses the same dictionary -based syntax.
Suchit shah replied to RAMAKRISHNA T on 30-Dec-11 07:33 AM

Session object store information between HTTP requests for a particular user,  while application object are global across users.
sessions allows information to be stored in one page and accessed in another,and it supports any type of object,including your own custom data types.

Application state allows you to store global objects that can be accessed by any client.

dipa ahuja replied to RAMAKRISHNA T on 30-Dec-11 10:08 AM
Session object is for individual user sessions, it different for different users. Application object is for the whole application, any user can access those objects, they are same acorss the application. 

check this article

 http://www.aspfree.com/c/a/ASP.NET/Application-and-Session-Objects-in-ASP.NET/

Riley K replied to RAMAKRISHNA T on 31-Dec-11 06:37 AM


Session state:

- The session object is used to maintain the session of each user. A user gets a session id when he enters in to an application. 

This Id will delete when he leave from that application. If he enters again he will get a different session Id.
- Session allows information to be stored in one page and access in another page and support any type of object.

Means that a user can access his session data only as Session data is specific to to user browser session only.

Application state:

- But the application object, the Id is maintained for whole application.
- Application state allows storing global objects that can be accessed by any client

It is global in nature and its accessible to each user of the website . Application.Lock() and Application.Unlock() are used while writing data to application object.

Regards.