Showing posts with label Session Variable. Show all posts
Showing posts with label Session Variable. Show all posts

Monday, 28 August 2017

Application and Session Variable of Asp.Net

In this post, I will explain about the Application and Session Variable of Asp.Net

Application and Session variables can be used to store values that are global either to a particular user or to all users. Application variables and session variables stored in memory on the server works faster than storing and retrieving information in a database.

Application Variables

The Application variables are variables maintained on server-side by asp.net runtime. Application variables are the variables which remain common for the whole application for all the users. Application variable can be used across the whole application by any user. And they will end when the application stops or probably when they are killed forcibly. The ideal example of these kinds of variables is 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. We can use application start and application end events of global.asax file to start and end application variable.

Session Variables

The session variables are variables maintained on server-side by asp.net runtime. Each user is identified by a unique number called SessioID. 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 different copy. But they will end when a particular user session ends or probably when they are killed forcibly. The ideal example of this kind of variables is user id, User name. We can show massage like "Welcome Programming Trends" on every page of your site till Programming Trends logs off. We can use session start and session end events of global.asax file to start and end session variable.