Application and Session Objects in ASP.NET - Application Objects
(Page 3 of 4 )
As we saw in the previous section, sessions help us preserve data on a per user basis. What if we want to initialize variables that are available in a session and that are the same for all users? This means that a change in the value of an application variable is reflected in the current sessions of all users. For example, we may like to fix variables like tax rate, discount rate, company name, etc., that will be specified once for all variables we can access in a session. This is where application variables come in. Heck, they can even be used to show legal notices at the bottom of every page!
Creating an application variable is similar to session variables.
Application
(“legal_notice”) = “No part of this article may be reproduced without prior permission”
There is a concern when changing the value of an application variable: at any particular instant, multiple sessions might be trying to change the value, although only one session can be allowed to change it. ASP.NET has an in built mutual exclusion for dealing with these types of problems.
- Application.Lock – Locks the application variables
- Application.Unlock – Unlocks the application variables
Once application variables are locked sessions that attempt to change them have to wait.
Next: Practical Examples Showing the Use of Sessions >>
More ASP.NET Articles
More By Aayush Puri