Blog Reader RSS LoveCherry 技术无极限 GEO MVP MS Project开源技术

session相关问题

在asp.net中,如何使得当session过期后自动跳转到登陆页呢?下面我提供一个简单的方法:
 private void Page_Load(object sender, System.EventArgs e)

{

      Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5));

      if(Session[“IsUserValid”].ToString()==””)

            Server.Transfer(“Relogin.aspx”);

}
在page.load事件中,加入response.addheader方法,当session过期失效后的5秒,页面就会自动刷新,这
个时候,判断到session失效了,之后系统自动跳转了

如何使得关闭页面立即结束会话session
Session_OnEnd()   will   not   be   called   if   the   user   just   closed   his   window   and   will   be   called   when   the   Session   times   out  
   
  1.   in   your   page   (not   always   work,   for   example,   when   the   user   browser   away   from   your   site)  
  <script   language="javascript">  
  function   window.onunload()  
  {  
      if   (event.clientX   <   0   &&   event.clientY   <   0)  
          window.open("logout.aspx","logout");  
  }  
  </script>   
in   logout.aspx,   call  
  <%  
  Session.Abandon()  
  %>  
   
  2.   use   a   method   which   doesn't   use   Session_OnStart/Session_OnEnd,   for   example,   keep   a   DataTable   in   an   Application   variable   and   record     users'   last   access   time,   the   DataTable   is   checked   every   time   a   user   sends   a   request,   if   the   access   time   for   any   user   was   10   minutes   ago,   you   remove   the   user   from   the   DataTable  
但是我发现这种关闭页面即关闭SESSION的方法很不实际.

posted @ 2008-04-10 14:05  大宋提刑官  阅读(218)  评论(0编辑  收藏  举报