重置会话重定向到另一个页面

时间:2013-11-18 11:02:44

标签: c# asp.net session

我正在开发合同管理网络应用程序。我想在用户更改页面时清除所有会话变量。例如,假设用户的当前页面是“Default.aspx”,当用户将页面更改为“Profile.aspx”时,我在此页面上创建3个会话变量。应删除3个会话变量。

请注意:我使用的是ASP.NET。

2 个答案:

答案 0 :(得分:2)

在Profile.aspx的 Page_Load 中尝试类似的内容:

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

答案 1 :(得分:-1)

尝试

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.