Why isnt the session timeout working when set to SqlServer?

前端 未结 3 1693
花落未央
花落未央 2021-01-05 23:18

I have the line:


相关标签:
3条回答
  • 2021-01-05 23:39

    You may be able to control the timeout of the session by setting the timeout of the forms authentication cookie:

    FormsAuthenticationTicket authTicket = 
    new FormsAuthenticationTicket(1, // version
    txtUserName.Text,
    DateTime.Now, 
    DateTime.Now.AddMinutes(1),
    false,@"\");
    

    That way the user looses contact with the session after 1 min.

    0 讨论(0)
  • 2021-01-05 23:43
    1. Make sure the SQL Server Agent service is running

    2. Right-click on the SQL Server Agent job named ASPState_Job_DeleteExpiredSessions and click "View History" - Make sure this job is running successfully every 1 minute.

    In my case, somehow (probably during one of multiple installs involving named instances) my SQL Server Agent had its property Connection -> Alias Localhost Server set to just the server name and not the servername\instancename.

    When this change happened, the ASPState_Job_DeleteExpiredSessions appeared to run indefinitely and could not be stopped. So, I attempted to re-start the SQL Server Agent service, but it would not start back up. However, once I changed the Connection -> Alias Localhost Server property to servername\instancename, SQL Server Agent started right back up and the ASPState_Job_DeleteExpiredSessions job started running successfully once a minute like it should.....and this obviously solved my timeout problem.

    0 讨论(0)
  • 2021-01-05 23:46

    If you're using SQL Server Express, it's because there is no SQL Server Agent to execute the DeleteExpiredSessions procedure.

    Here is a possible workaround to the problem:

    In the stored procedure that updates the session, I have added SQL from the DeleteExpiredSessions procedure to the update session stored procedure (I can't remember the name) so it checks for old sessions, deletes the old session, and then updates the current sessions. The stored procedure that updates the session runs on every click anyway, so I added two more lines that remove old sessions before the session is updated. This seems to work fine.

    0 讨论(0)
提交回复
热议问题