asp.net-mvc - ASP.NET MVC 中何时调用 Session_End()?

标签 asp.net-mvc web-config session-state session-timeout

我在 ASP.NET MVC 2 项目中配置了我的 Web.Config 文件,如下所示:

<sessionState mode="InProc" timeout="1"/>

并在Global.asax.cs中添加以下内容:

protected void Session_End(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Session_End");
}

protected void Session_Start(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Session_Start");
}
当新用户访问网站时,将调用

Session_Start()。我本希望 Session_End() 在 1 分钟空闲时间后被调用,但事实并非如此。我错过了什么吗?

最佳答案

记住这一点:

If you don't save anything into the session, the session_end will not fire. If you're saving data in the session in the first request, and calling abandon in the same request the session_end will also not fired.

Hope this helps!

T

顺便说一句: ASP.NET Session_End event not firing

关于asp.net-mvc - ASP.NET MVC 中何时调用 Session_End()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2373209/

相关文章:

c# - 之间的差异

c# - 有没有办法将 app/web.config 分成 2 个文件?

c# - IIS 8 上的内部服务器错误 500

ASP.NET MVC : how to prevent a session lock?

c# - ASP.NET MVC : Requested registry access denied when creating performance counters

c# - 如何在 Visual Studio 中发布类库?

c# - 从 session Cookie 实例化 ASP.NET session

asp.net-mvc - 如何在 SQL Server 中为 Asp.Net MVC 4 应用程序或 WebRole 应用程序存储 asp.net session 状态?

javascript - Angular 路由模板 url 是否支持 ASP.Net MVC 5 项目中的 *.cshtml 文件?

asp.net - 以编程方式设置自定义404错误页面