2

I would like to display the "Your session has expired" on logon page if session has been idle for given 5 minutes.

What should the time out value be for Sql Session State and Form Authentication Time Out:

  1. same?
  2. session state> form timeout
  3. Form time out > session time.

ideally, if someone could explain the diff between above will be appreciated.

Currently, my code looks like below and Session["SessionID"] is not Null even after Login redirection for idle of 5 minute:

On Session_Start()
 Session["SessionID"] = Guid.NewGuid();

On LogOn.cshtml:

 @{
        string sessionExpiredMsg = string.Empty;

        HttpContext ctx = HttpContext.Current;
        if (ctx.Session["SessionID"] == null)
        {
            sessionExpiredMsg = "Your session has expired. Please re-login again.";
        }
    }
@

On web.config:

<sessionState
timeout=5....

<authentication mode="forms"
 timeout=5....

Thank you.

0

1 Answer 1

5
  • Session state timeout means that your asp.net session will expire in x minutes. It doesn't mean that your're not authenticated anymore.
  • Forms timeout means that after x minutes, you'll be prompted to log in again(not authenticated anymore).

It's not a problem if your sessionstate timeout lasts longer that your forms timeout because once you'll log in again you will retrieve the last one if not expired.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks lnu, i've updated my question with codes which is not working.
ctx.Session["SessionID"] still contains the value even after login redirection. Not sure why.
yep that is what I used, and doesn't work. Session is not null even redirection to Login page
Try to put 10 minutes for your forms timeout and 1 minute for your session. I've done the same as you and my session is empty( and Session.IsNew==true) after 1 minute. But it keeps the same sessionid.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.