how to check session is expired or not if expired then redirect to login page

 

在项目中,如果客户打开页面时间过久容易导致页面Session过期,再进行任何操作时都会提示“Asp.Net session has expired”,这样毕竟都用户不太友好,所以需要解决一下,判断Session是否过期,如果过期进行一下提示或者刷新一下页面。

void Page_Load()
{
   if (Context.Session != null)
   {
      if (Session.IsNewSession)
      {
         string cookieHeader = Request.Headers["Cookie"];
         if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
         {
            Response.Redirect("sessionTimeout.htm");
         }  
      } 
   }
}

相关文章:

  • 2021-08-06
  • 2021-09-15
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2021-07-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案