ASP.NET MVC 中何时调用 Session_End()?

发布于 2024-08-24 11:16:43 字数 558 浏览 5 评论 0原文

我在 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 分钟空闲时间后被调用,但事实并非如此。我错过了什么吗?

I have configured my Web.Config file as follow in a ASP.NET MVC 2 project:

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

And added the following in 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() is called when a new user goes on the website. I would have expected Session_End() to be called after 1 minute of idle time, but it's not the case. Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花海 2024-08-31 11:16:43

请记住这一点:

如果你没有在会话中保存任何内容,session_end将不会
火。如果您在第一个请求中将数据保存在会话中,并在第一个请求中调用放弃
同样的请求,session_end 也不会被触发。

希望这有帮助!

T


ASP.NET Session_End 事件未触发

Remember this:

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

btw:
ASP.NET Session_End event not firing

友欢 2024-08-31 11:16:43

要有耐心。应调用该事件,但不一定在超时后立即调用。

您可以尝试从浏览器:开始会话,等待> 1 分钟,以某种方式进行回发

这应该有助于验证超时是否有效,我认为您还会看到当时发生 SessionEnd。否则,只需等待并开始其他会话。系统有时会调用它。

Be patient. The event should be called, but not necessarily right after the timeout.

You could try from a Browser: Start a session,wait > 1 minute, do a Postback somehow

This should help to verify that the Timeout works and I think you will also see the SessionEnd happening at that time. Otherwise, just wait and start some other sessions. The system will come around o calling it sometime.

你没皮卡萌 2024-08-31 11:16:43

测试提示:使用Session.Abandon,这样您就不必弄乱实际的 web.config 值。只是不要在同一请求期间设置会话值并调用 Session.Abandon ,否则它将不会被存储。

Tip for testing: Use Session.Abandon so you don't have to mess with your actual web.config value. Just don't set a session value and call Session.Abandon during the same request or it won't get stored.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文