这真是一个奇怪的问题。

https://files.cnblogs.com/cookieswolf/errortest.rar

这真是一个奇怪的问题。

启动页面webform1.aspx
private void Button1_Click(object sender, System.EventArgs e)
  {
   string w=Application["dsf"].ToString();
  }
Application["dsf"]是没有的我故意来引发错误。


Global.asax

protected void Application_Error(Object sender, EventArgs e)
  {
   HttpApplication application = ( HttpApplication )sender;
  
   HttpContext context = application.Context;
   Exception exceptions;
   if ( context.Server.GetLastError().GetBaseException() is Exception )
   {
    exceptions = ( Exception ) context.Server.GetLastError().GetBaseException();
    Session["hehe"]="ERROR: " + exceptions.Message + "\r\n" + exceptions.InnerException;
    Response.Redirect(HttpContext.Current.Request.ApplicationPath+"/webform2.aspx");
    }
   else
   {
    exceptions = new Exception("Unknow Error", context.Server.GetLastError());
    throw exceptions;
   }

  }
Session["hehe"]是用来存储错误信息,用来在weform2中显示。
webform2.aspx:
Label1.Text=(string)Session["hehe"];

但是很奇怪Session["hehe"]是空的不存在。

这种情况只是在Application,Session引发的错误存在。虽然用别的方法解决了。但是非常不理解。请大家帮忙看一下。谢谢。

posted @ 2005-06-02 14:53  傅红雪  阅读(1532)  评论(6编辑  收藏  举报