Why aren't session objects deleted after a wait period in Asp.Net?

Why aren't session objects deleted after a wait period?

I am using Asp.Net 4.0 and the 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"/>

If I have not been active in the browser for 10 minutes, I should not delete the Session object. But after 10 minutes I can access the Session variable. Did I miss something?

EDIT:

If I access the session variable after 10 minutes, as shown below, I should not get NULL

  var myObj = Session["MyKey"] as MyClass;

mObj is not NULL after 10 minutes.

+3
source share
3 answers

DeleteExpiredSessions, ASPState_Job_DeleteExpiredSessions ( InstallSqlState.sql).

DELETE FROM ASPStateTempSessions WHERE Expires < GETUTCDATE()

, , Expires , utc. , a SELECT * FROM ASPStateTempSessions WHERE Expires < GETUTCDATE(). , , ASPState_Job_DeleteExpiresSessions .

( ); SQL Server Express SQL-? ?

+6

"session" "null", ( ), ( , SessionEnd SessionStart) . ? ?

+2

, , SQL Server, , .
, SQL Server Express , .

, , , . , .

Thus, your options are to upgrade to the version of SQL server on which SQL Server Agent is installed, or install something to manually execute the stored procedure to clear expired sessions.

In any case, you can use InProc sessions, which are automatically cleared. But I assumed that since InProc is the default, there is a reason why you switched to SQL Server.

0
source

Source: https://habr.com/ru/post/1790757/


All Articles