为什么在Asp.Net中的超时时间过后,会话对象没有被删除? [英] Why Session objects are not removed after Timeout period in Asp.Net?
问题描述
我正在使用Asp.Net 4.0,并且会话状态配置如下所示.
I am using Asp.Net 4.0 and Session state is configured as shown below.
<sessionState mode="SQLServer" cookieless="false" timeout="5"
allowCustomSqlDatabase="true"
sqlConnectionString="data source=.\SqlExpress;initial catalog=App_SessionState;user id=sa;password=xxxxxxxx"/>
如果大约10分钟我没有在浏览器中活动,则不应删除Session对象.但是10分钟后,我仍然可以访问Session变量.我在这里想念什么吗?
If I have not activity in browser for about 10 mins, shouldn't the Session object be removed. But after 10 mins I can still access the Session variable. Am I missing something here?
如果我在10分钟后访问会话变量,如下所示,我应该不会得到 NULL
If I access a session variable after 10 mins as shown below shouldn't I get NULL
var myObj = Session["MyKey"] as MyClass;
10分钟后,mObj不为空.
mObj is not NULL after 10 mins.
推荐答案
已安装名为DeleteExpiredSessions
的存储过程,该存储过程是从作业ASPState_Job_DeleteExpiredSessions
调用的,并且每分钟执行一次(如果我正确阅读了InstallSqlState.sql文件, ).
There's a stored procedure installed called DeleteExpiredSessions
, called from the job ASPState_Job_DeleteExpiredSessions
, and is executed every minute (if I read the InstallSqlState.sql file correctly).
该过程基本上会调用DELETE FROM ASPStateTempSessions WHERE Expires < GETUTCDATE()
因此,如果未删除对象,请检查Expires列,并确认您要与 utc 日期进行比较.如有疑问,请执行SELECT * FROM ASPStateTempSessions WHERE Expires < GETUTCDATE()
.另外,请确保您的ASPState_Job_DeleteExpiresSessions
已启用并且可以正常工作.
So, if objects aren't removed, check the Expires column, and verify that you're comparing with the utc date. If in doubt, do a SELECT * FROM ASPStateTempSessions WHERE Expires < GETUTCDATE()
. Also, make sure that your ASPState_Job_DeleteExpiresSessions
is enabled and working.
一个快速(完全未经证实的想法); SQL Server Express是否随SQL Agent一起提供?它启用并能够执行计划的作业吗?
A quick (and totally unconfirmed idea); do SQL Server Express come with the SQL Agent? Is it enabled and able execute scheduled jobs?
这篇关于为什么在Asp.Net中的超时时间过后,会话对象没有被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!