asp.net – Session_End不启动?

当他的会话超时时,我想登出一个用户。所以在Global.asax中使用以下代码:
protected void Session_End(object sender,EventArgs e)
{
    FormsAuthentication.SignOut();
}

但似乎session_end从不触发。任何想法如何解决?我使用ASP.NET与默认设置。

解决方法

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

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.

相关文章

引言 本文从Linux小白的视角, 在CentOS 7.x服务器上搭建一个...
引言: 多线程编程/异步编程非常复杂,有很多概念和工具需要...
一. 宏观概念 ASP.NET Core Middleware是在应用程序处理管道...
背景 在.Net和C#中运行异步代码相当简单,因为我们有时候需要...
HTTP基本认证 在HTTP中,HTTP基本认证(Basic Authenticatio...
1.Linq 执行多列排序 OrderBy的意义是按照指定顺序排序,连续...