【问题标题】:ASP.NET: How to end session when the user clicks log-out?ASP.NET:当用户单击注销时如何结束会话?
【发布时间】:2016-04-27 03:19:40
【问题描述】:

我想问您如何在用户单击注销时结束 asp.net 中的会话,因为我的一位教授发现,当他单击注销并单击浏览器上的后退按钮时,会话仍然处于活动状态,他希望结束特定会话,而这正是您单击注销时会发生的事情。

谢谢。

【问题讨论】:

标签: c# asp.net session web hyperlink


【解决方案1】:

Abandon 方法应该可以工作(MSDN):

Session.Abandon();

如果您想从会话中删除特定项目,请使用 (MSDN):

Session.Remove("YourItem");

编辑:如果您只想清除一个值,您可以这样做:

 Session["YourItem"] = null;

如果要清除所有键,请执行以下操作:

 Session.Clear();

如果这些都不适合你,那就是有问题了。我会检查您在哪里分配值,并在您清除值后验证它没有被重新分配。

简单检查:

 Session["YourKey"] = "Test";  // creates the key
Session.Remove("YourKey");    // removes the key
bool gone = (Session["YourKey"] == null);   // tests that the remove worked

这是凯尔西的回答Click Here

【讨论】:

    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 2014-10-30
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 2018-08-17
    相关资源
    最近更新 更多