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的方法很不实际.

转载于:https://www.cnblogs.com/onlyendure/archive/2008/04/10/1146721.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值