前不久作一个wap页面每隔一段时间不动页面就出现session过期,一直想解决它。

 
session每次过期都要经过glable文件中的Application_Error方法,在其中验证,判断返回登陆页面就可以了
 
protected void Application_Error(Object sender, EventArgs e)
  {   
   string URL = HttpContext.Current.Request.Url.ToString ();
   if(Server.GetLastError() is HttpUnhandledException)
   {
    Server.ClearError();
    this.Server.Transfer("Login.aspx?ref=viewstate",true);
   }
   else
   {
    Server.ClearError();
    this.Server.Transfer(URL,true);
   }
//    Exception objErr = Server.GetLastError().GetBaseException();
//    string  objInner = Server.GetLastError().InnerException.ToString();
//    string  strErr = Server.GetLastError().Message.ToString();
//    string  strSource = Server.GetLastError().Source.ToString();
//
//    string strSender = sender.ToString();
//    string typeSender  = sender.GetType().ToString();
//    string strE = e.ToString();
//    string typeE = e.GetType().ToString();
//    this.Session.Clear();
//    this.Application.Clear();
//    this.Server.Transfer("Login.aspx?ref=viewstate",true);
   
  }