locked
Cannot get ASP.Net Web Forms application to timeout RRS feed

  • Question

  • User636460510 posted

    I am working on an ASP.Net web forms application.

    I want the site to timeout after a certain period, which should be simple, however, I cannot seem to get this to happen as expected.

    I have tried changing the timeout settings in web.config, as well as in IIS. I am in SQLServer Session Mode.

    Code written in the Session_End function of the Global.asax file never executes, regardless of what settings I use for timeout.

    Examining the session cookie and ASPStateTempSessions table in SQL Server indicate that the settings that I am changing in web.config are indeed changing the timeout values of the session, however, there is never anything to suggest that the site is ACTUALLY timing out.

    I do not know where else to look for timeout settings, or what may be preventing me from generating a timeout.

    Thursday, January 23, 2020 4:21 PM

All replies

  • User475983607 posted

    ASP.NET does not timeout.  Are you referring to user Session timeout?  Are using SQL to store Session?  If so, SQL Server mode does not trigger the Session_End. The InPorc mode does to clear server memory otherwise the app will eventually run out of memory.  SQL server mode does not have this issue.   You can certainly set the Session timeout which will expire the Session cookie.

    <sessionState 
                mode="SQLServer"
                sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"
                cookieless="false" 
                timeout="20" 
        />

    https://support.microsoft.com/en-us/help/317604/how-to-configure-sql-server-to-store-asp-net-session-state

    Thursday, January 23, 2020 4:29 PM
  • User636460510 posted

    Thank you for your response!

    Yes, I am referring to user session timeout. Apologies, I am relatively new to this.

    If SQL Server Mode does not trigger Session_End, then what would be your recommended strategy to redirect to a different page upon session timeout?

    Thursday, January 23, 2020 4:36 PM
  • User475983607 posted

    Just check if the Session variable is empty.

    if(Session["TheVariable"] == null)
    {
       Response.Redirect("/to/the/url.aspx");
    }

    Place the code in your master page Page_Load event.  If you are not using master page then use the Application_AcquireRequestState or a later event in the Global.asax.

    Thursday, January 23, 2020 4:55 PM