Differences in forms auth timeout and session timeout

22,483

Solution 1

A session starts every time a new user hits the website, regardless of whether or not they are anonymous. Authentication has very little to do with Session.

Authentication timeout is the amount of time that the authentication cookie is good for on the user's browser. Once the cookie expires, they must re-authenticate to access protected resources on the site.

So, if Session times out before the Authentication cookie - they are still authenticated, but all their session variables disappear, and may cause errors in your website if you are not disciplined in checking for nulls and other conditions brought about by missing session.

If Authentication times out before the session, then all their session variables will still exist, but they won't be able to access protected resources until they log back in again.

Solution 2

as expected.

e.g. if your session times out after 20 minutes, your session-variables will be lost. but the user could access the pages which are protected by the authentication.

if the authentication times out, the user could not access the page which it protects, and the state of the session is irrelevant.

Share:
22,483
Nick
Author by

Nick

Updated on October 08, 2020

Comments

  • Nick
    Nick over 3 years

    The session state timeout is set using this web.config element

    <sessionState mode="InProc" cookieless="false" timeout="120" />
    

    The forms auth is configured using this web.config element

    <system.web>
      <authentication mode="Forms">
        <forms loginUrl="Login.aspx"
               protection="All"
               timeout="30"
               name=".ASPXAUTH" 
               path="/"
               requireSSL="false"
               slidingExpiration="true"
               defaultUrl="default.aspx"
               cookieless="UseDeviceProfile"
               enableCrossAppRedirects="false" />
      </authentication>
    </system.web>
    

    What is the difference between the timeouts specified in each of these elements? If both are different, how would it work?