Reputation:
I am working on a contract management web application. I want to clear all my session variables when user change the page. For example suppose the current page of user is "Default.aspx" and I create 3 session variables on this page when the user changes the page to "Profile.aspx" 3 session variables should be removed.
Please notice: I am using ASP.NET.
Upvotes: 1
Views: 1889
Reputation: 10010
Try
Session.RemoveAll (); //Removes all session variables. Just calls the Session.Clear() method in its implementation, so for ease you can say there is no difference.
OR
Session.Abandon(); //Releases sessionstate itself to be garbage collected when chance arrives. Only point to note that it happens just before the current request is fulfilled.
OR
Session.Clear(); //Releases all key value pairs immideatly and make them available for garbage collection. But the Resource used by SessionState Collection are intact and booked as is.
Upvotes: -1
Reputation: 44550
Try something like that in Page_Load of Profile.aspx:
if (!IsPostBack)
{
Session.Clear();
}
Upvotes: 2