Differences of Application and Session objects.

 Posted by Ddd on 2/10/2011 | Category: ASP.NET Interview questions | Views: 3840 | Points: 40

Application and Session objects are used for temporary data storage.
They store their data in the RAM of the web server.



1)It is returned through the Application property of the HttpContext class.

Its class is HttpApplicationState.

Namespace: System.Web

format of data storage:

ex: Application["hits"]=1;

"hits": key

1: value

2)Stores the data till the web application is shut down or we manually release its data using null/nothing or the Clear method is called.

3)It is created as soon as the web application is launched on the server.

4)Typical uses:


a)Calculate the hits of a particular page of a web site.

b)Calculate the time taken for the execution of a web page.

c)Storing data of a readonly table/documentation file and displaying it across different pages.

5)It has no ID.


1)It is returned through the Session property of the HttpContext class.

Its class is HttpSessionState.

Namespace: System.Web.SessionState.

format of data storage:

ex: Session["uname"]="ddd";

"uname": key

"ddd": value

2)Stores the data as specified by the Timeout property. Default Timeout is 20 minutes.

Timeout can be increased/decreased.
We can release data using null or Clear() method

Session can be killed using Session.Abandon() method.

Application object has no Abandon() method.

3)It is created when:

a)a unique instance of the browser is launched.

b)if the current instance of the browser is open and Timeout occurs/ Abandon() method is called.

c)if Session_End() event handler fires.

4)Typical uses:



a)MailBox: enter username on Login Page. The name is displayed in the mailbox page
when the mailbox page is opened from Login Page

b)Fetch data from database and display it on different pages.


count the clicks of a button

we do not use Session object to calculate the number of Page hits since the Session data is reset everytime unique instance of the browser opens.

d)Shopping carts: display the data of a GridView in other page

e)Internet Usage: Calculate the internet Bill and the MB's used

5)Session object also has a SessionID.



1)Global.asax file is used for the initialization of the Application and Session objects that can then be used on different web pages of a web site.

2)Appication object is heavier as compared to Session object.So, we do not use

Application object for tasks like enter username on one page and displaying it

on another.

3)Session object stores the data on per user basis, while the Application object's
data is shared among the different users.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response