我希望实现当Session失效时,跳转到登录页面。
下面是我的做法,但不能实现:
  protected void Session_End(object s,EventArgs e)
  {
    HttpApplication app = (HttpApplication)s;
    HttpContext context = app.Context;
    context.Response.Redirect("login.aspx");
  }是不是我的思路有问题?
能不能给我个方法。
附:我希望在应用程序级做这样的处理。

解决方案 »

  1.   

    if(Session["x"] == null) Response.Redirect("login.aspx");
      

  2.   

    不能在应用程序级做的,即使做,也不能在Session_End事件里做,
      

  3.   

    在在应用程序级处理会陷入死循环
    Page_Load:if(Session["x"] == null) Response.Redirect("login.aspx");
      

  4.   

    b/s是 是单一 服务 面向 多用户的不能那么多只能在页面程序端 判断if(Session["user"] == null) Server.Transfer("login.aspx", false);
      

  5.   

    我现在需要在应用程序级做,有方法实现吗?我对这个方式的理解是:
    当一个用户的Session结束时,将会触发Session_End事件,那么我就将这个用户的URL换为"Login.aspx"。
      

  6.   

    看来我只能在Application_Error事件里处理了!
      

  7.   

    protected void Application_PostAcquireRequestState( object sender, EventArgs e )
      {
        if(HttpContext.Current.Request.Url.ToString().ToLower().IndexOf("login.aspx") == -1)
        {
          if (HttpContext.Current.Session["x"] == null)
            HttpContext.Current.Response.Redirect("Login.aspx");
        }    
      }
      

  8.   

    我希望实现当Session失效时,跳转到登录页面。
    ...
    附:我希望在应用程序级做这样的处理。-----------------------public event System.EventHandler BeginRequest
    在 ASP.NET 响应请求时作为 HTTP 执行管线链中的第一个事件发生。public event System.EventHandler AuthenticateRequest
    当安全模块已建立用户标识时发生。  public event System.EventHandler AcquireRequestState
    当 ASP.NET 获取与当前请求关联的当前状态(如会话状态)时发生。public event System.EventHandler EndRequest
    在 ASP.NET 响应请求时作为 HTTP 执行管线链中的最后一个事件发生。
      

  9.   

    事件先后
    1.x Application_BeginRequest
    2.x Application_AuthenticateRequest
    3.x Session_Start
    4.x Application_EndRequest