Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Difference between Application and session variable
Posted 29-Sep-11 20:48pm
TanmoyD837
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Application variables are the variables which remain common for the whole application for all the users… Their value can be used across the whole application by any user… And they die only when the application stops or probably when they are killed forcibly… The ideal example for these kind of variables are site counter… We can find out how many people accessed a particular site since the time it went live via application variables and incrementing the same on ever session start..
 
where as
 
Session variables are variables which remain common for the whole application but for one particular user. They also can be used across the whole application but each user will have a copy… But they die when a particular user session ends or probably when they are killed forcibly… The ideal example for this kind of variable are user id… You might want to show "Welcome Prabha " on every page of your site till Prabha logs off… So in session start you set a variable to "Welcome Meetu Choudhary" and kill it on end of session…
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Application object is used to store data which is visible across entire application and shared across multiple user sessions. Data which needs to be persisted for entire life of application should be stored in application object.
 
In classic ASP, application object is used to store connection strings. It's a great place to store data which changes infrequently. We should write to application variable only in application_Onstart event (global.asax) or application.lock event to avoid data conflicts. Below code sample gives idea
 

 
Session object:
 
Session object is used to store state specific information per client basis. It is specific to particular user. Session data persists for the duration of user session you can store session's data on web server in different ways. Session state can be configured using the <session State> section in the application's web.config file.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thursday, May 27, 2004
Difference between Application Variables and Session Variables<pre lang="text">
 
-----Original Message-----
From: Vishal Joshi
Sent: Thursday, May 27, 2004 1:54 PM
To: Rakesh Ambudkar
Subject: RE: What does this mean
 
I presume that there are 2 types of variables in the discussion below:
Session
Application
 
Application variables are the variables which remain common for the whole application… Their value can be used across the whole application… And they die only when the application stops or probably when they are killed forcibily… The ideal example for these kindof variables are site counter… We can find out how many people accessed a particular site since the time it went live via application variables and incrementing the same on ever session start..
Session variables are variables which remain common for the whole application but for one particular user. They also can be used across the whole application… But they die when a particular user session ends or probably when they are killed forcibily… The ideal example for this kindof variable are user id… You might want to show "Welcome Vishal" on every page of your site till vishal logs off… So in session start you set a variable to "Welcome Vishal" and kill it on session end…
All these methods like session start, session end, application start, application end are found in global.asax and that’s the reason global.asax is one for the whole ASP.Net application…
I hope this provides you with the info that you needed…
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 540
1 Sergey Alexandrovich Kryukov 420
2 George Jonsson 328
3 Pheonyx 218
4 OriginalGriff 215
0 OriginalGriff 4,813
1 CPallini 3,890
2 Sergey Alexandrovich Kryukov 3,274
3 George Jonsson 2,552
4 Gihan Liyanage 2,186


Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 30 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100