Reputation: 3364
I have several pages in my application. I have used a session variable called "Session["Variable"]" that is set in page1 and page2. That means The scope should be in page1 and page2. If you go out any of these page will clear the above session variable. Is there any solution to clear the particular session varible in the application level. i.e i don't want to write the code for each and every pages...
Upvotes: 1
Views: 238
Reputation: 6577
Once you set the session in an asp.net application, the scope of this session is available in everywhere. So, in your case, u can just write one common function for checking the page1 and page2.
Upvotes: 0
Reputation: 1107
If you used MasterPages or derive your pages from a base class, you can use a switch case and determine whether or not the current page is Page1, Page2 or something else. If it is "something else", remove the key from the session.
IE: Switch case in the Page_load of the masterpage
Upvotes: 0
Reputation: 43207
Session key once created is accessbile in all pages of the asp.net application and not just within the once where it was added or modified.
use Session.Remove() if you need to explicitly remove a variable/key from session.
Session.Remove("Variable");
Additionally,
Session.RemoveAll(); //Removes all keys from current session.
Session.Abandon(); //Abandon the current session.
Upvotes: 1