user2796487
user2796487

Reputation:

Reset Session on redirect to another page

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

Answers (2)

Microsoft DN
Microsoft DN

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

Andrei
Andrei

Reputation: 44550

Try something like that in Page_Load of Profile.aspx:

if (!IsPostBack)
{
   Session.Clear();
}

Upvotes: 2

Related Questions