What exactly Difference between Application and Session ?
-
Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..
According to Wikipedia[^], "a web application is an application that is accessed via a web browser over a network such as the Internet or an intranet. The term may also mean a computer software application that is hosted in a browser-controlled environment (e.g. a Java applet) or coded in a browser-supported language (such as JavaScript, possibly combined with a browser-rendered markup language like HTML) and reliant on a common web browser to render the application executable." By comparison, a browser session starts when an individual user accesses or logs onto a particular website and concludes when the user logs off, closes the browser, or clicks away from that website. The session may or may not involve authentication.
-
Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..
satyamzen wrote:
While i went to an interview interviewer asked me Difference between Application and Session ?
I guess he has asked about "Application State" Not "Application" . You can explain them in following way.
System.Web.HttpApplicationState
class is used to maintain the Application State For ASP.NET Application.It provides methods for storing information which can be accessed globally means it common for the all used. As For Example : Storing Info At Application Variable :Application["Title"] = "Welcome";
// Reading the Information from application variable
string Title;
if (Application["Title"] != null)
Title = Application["Title"].ToString();On the other hand Session stored on server side and its unique for each and every user. We can interact with Session State with
System.Web.SessionState.HttpSessionState
class, because this provides built in Session Object with Asp.Net Pages. As For Example : Following code is used for storing a value to session//Storing UserName in Session Session\["UserName"\] = txtUser.Text;
Now, let see how we can retrieve values from Session
//Check weather session variable null or not
if (Session["UserName"] != null)
{
//Retrieving UserName from Session
lblWelcome.Text = "Welcome : " + Session["UserName"].ToString();
}
else
{
//Do Something else
}Below are the associated events that are used for Session and Application State. This are events for
Global.asax
file. For Application :Application_Start, Application_End
For Session :Session_Start and Session_End
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Hi all, While i went to an interview interviewer asked me Difference between Application and Session ? Application common for all users but session is user level, but he didn't convinced with my answer. Please explore on my question. Thanks..
The simplest answer to that question would be that an Application or variables in Application state are initialized when the application receives the first user request. Data in the application state is common to all users. Application variables generally get recycled during Application Pool recycling [This is my understanding, somebody please confirm!!]. Session on the other hand is user specific and starts when the server receives the first request from a user browser and ends after the user closes the browser. Each user gets a separate share of memory for his session data and hence Session variables have to be used cautiously. Also, one user can open more than one session from the same computer using different browsers, i.e. I can get two session to CP and login using 2 different logins, from IE and Firefox, simultaneously. HTH!!
-
The simplest answer to that question would be that an Application or variables in Application state are initialized when the application receives the first user request. Data in the application state is common to all users. Application variables generally get recycled during Application Pool recycling [This is my understanding, somebody please confirm!!]. Session on the other hand is user specific and starts when the server receives the first request from a user browser and ends after the user closes the browser. Each user gets a separate share of memory for his session data and hence Session variables have to be used cautiously. Also, one user can open more than one session from the same computer using different browsers, i.e. I can get two session to CP and login using 2 different logins, from IE and Firefox, simultaneously. HTH!!
Dinesh Mani wrote:
ends after the user closes the browser
No, session does not end when user closed the browser. Session stored in Server Side. So If you are using Inproc session Session will automatically end when it reached the Session Timeout . So, If user close the browser, session will not end that time. Some of application may trap the Browser close and close the session from server end too. :) Thanks !
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Dinesh Mani wrote:
ends after the user closes the browser
No, session does not end when user closed the browser. Session stored in Server Side. So If you are using Inproc session Session will automatically end when it reached the Session Timeout . So, If user close the browser, session will not end that time. Some of application may trap the Browser close and close the session from server end too. :) Thanks !
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
I meant from a generic user perspective! That's why I had mentioned as "after the user closes the browser" and not as "when the user closes his browser". Since the Session expiration policy is different for different session policy I didn't want to get into the details! Anyway I guess I should have been very particular and specific! :)