Session_End 不触发? [英] Session_End does not fire?

查看:27
本文介绍了Session_End 不触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户的会话超时时将其注销.所以在 Global.asax 中使用了以下代码:

I want to sign out a user when his session times out. So used following code in Global.asax:

protected void Session_End(object sender, EventArgs e)
{
    FormsAuthentication.SignOut();
}

但似乎 session_end 永远不会触发.知道如何解决吗?我正在使用具有默认设置的 ASP.NET.

But seems session_end never fires. Any idea how can fix it? I'm using ASP.NET with default settings.

推荐答案

您可以在 Session_Start 中设置一些 Session 数据.没有这个,Session_End 将不会被触发.见这个

You may set some Session data in Session_Start. Without this, Session_End will not be fired. see this

这里要注意的另一件非常重要的事情是,如果您未在会话中保存任何内容,则 Session_End 事件将不会触发.会话中必须至少保存一次内容才能触发 Session_End 事件.这也意味着,如果您在第一个请求中保存会话中的某些内容并在同一请求中放弃会话,则 Sesison_End 事件将不会触发,因为会话中没有保存任何内容.

Also another very important thing to note here is that if you do not save anything in the session the Session_End event will not fire. There must be something saved in the session atleast once for the Session_End event to fire. This also means that if you save something in the session in the first request and abandon the session in the same request the Sesison_End event will not fire, as there was nothing saved in the session ever.

这篇关于Session_End 不触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆