0

As I am new to Sitecore and working on session time out functionality in Sitecore. Instead of redirecting to login page I've to display session time out warning message to end user and How to validate at server side whether user session is timeout or not?

How can this be achieved in Sitecore? Can it be done in Sitecore as same as normal ASP.net session timeout as below ?

if(Session["mykey"] != null)
{
  // Session is not expired
}
else
{
  //Session is expired
}

What is a better approach to implement it?

If there is any source related to better approach to validate session time out in Sitecore, Please provide blogs/articles. Any suggestion would be very helpful.

Thanks & Regards.

  • As @richard answered the asked question. Thanks, unfortunately not able to mark the answer as anwered because of less reputation.Hope so some one will mark it as anwered. – Kumari Dimple Sep 27 '18 at 19:07
  • No one but you can mark the answer. – Mark Cassidy Sep 29 '18 at 4:12
2

Yes - Sitecore is just an ASP.Net web application, so session works just the same. The same rules apply as any other .net web application.

Your method is one way to check that, you could also check the HttpContext.Current.Session.IsNewSession along with a check on existence of the session cookie like this:

public static bool IsSessionExpired()
{
    if (HttpContext.Current.Session != null)
    {
        if (HttpContext.Current.Session.IsNewSession)
        {
            string CookieHeaders = HttpContext.Current.Request.Headers["Cookie"];

            if ((null != CookieHeaders) && (CookieHeaders.IndexOf("ASP.NET_SessionId") >= 0))
            {
                // IsNewSession is true, but session cookie exists,
                // so, ASP.NET session is expired
                return true;
            }
        }
    }
}

Reference: http://www.beansoftware.com/ASP.NET-Tutorials/Find-If-Session-Expired.aspx

  • Thankyou for providing valuable information.It works and also verified. – Kumari Dimple Sep 27 '18 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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