8

Application logout automatically in few seconds, i want to increase it to 30mins.

I have done some code in web.config file but it doesn't work. i have researched many articles on it but i could not resolve it.

Web.config code :

<sessionState mode="InProc" timeout="1800"></sessionState>
    <authentication mode="Forms">
      <forms loginUrl="~/Login" timeout="1800">
      </forms>
    </authentication>
2
  • The configuration you show works. If your sessions still seem to time out, there's something else going on. Explain what your hosting environment looks like, show relevant code that uses the session and explain what behavior exactly you experience.
    – CodeCaster
    Aug 13, 2016 at 15:17
  • Isn't sessionState timeout supposed to be in minutes? It looks like in your code would be seconds (30 minutes * 60 = 1800)
    – Csaba Toth
    Jul 14, 2019 at 1:09

2 Answers 2

4

Session State & Authentication timeouts are in minutes not seconds. So, you should have

<sessionState mode="inProc" timeout="30" ></sessionState>
<authentication mode="Forms">
      <forms loginUrl="~/Login" timeout="30">
      </forms>
</authentication>

Also, you should be aware that the way this is setup, the authentication will timeout 30 minutes after it was granted while the session will extend the 30 minutes to be from last access. To make these two closer to syncing up, you should add slidingExpiration="True" to the forms element.

If, after these changes, it is still logging you out after a few seconds, take look at:

  1. Is the cookie getting created in the website? It's name will be .ASPXAUTH and it should be a session cookie.
  2. Are you closing the browser when the timeout occurs?
  3. Do you have multiple applications using the same authentication method?
2
  • The default for sessionState is slidingExpiration="True" so there is no need to set it implicitly
    – Dror
    Feb 5, 2017 at 18:51
  • slidingExpiration forces the timer to start over for expiration in some cases. But there are still many reasons to change the timeout period.
    – Jeff Siver
    Feb 6, 2017 at 20:40
-1

Another place this can be set is in your Global.asax file. If the sessionState isn't working in your web.config file, I suggest taking a look in there. Apparently the Global.asax file will override the web.config file. It can be set like this:

Session.Timeout = 30;//Timeout expects an integer representing minutes
2
  • I did this but is gave me an error Session state is not available in this context. Aug 13, 2016 at 16:47
  • I don't suggest this approach, but I tested it inside Session_Start without any error.
    – QMaster
    Mar 28, 2017 at 11:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.