ASP.NET MVC 中何时调用 Session_End()?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请记住这一点:
:
ASP.NET Session_End 事件未触发
Remember this:
btw:
ASP.NET Session_End event not firing
要有耐心。应调用该事件,但不一定在超时后立即调用。
您可以尝试从浏览器:开始会话,等待> 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.
测试提示:使用
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 callSession.Abandon
during the same request or it won't get stored.