在Global中Application_Error事件处理错误信息

在Global中 
protected void Application_Error(Object sender, EventArgs e)
  {
   Exception objErr = Server.GetLastError().GetBaseException();
   string error = "发生异常页: " + Request.Url.ToString() + "<br>";
   error += "异常信息: " + objErr.Message + "<br>";
   Server.ClearError();
   Application["error"] = error;
   Response.Redirect("~/ErrorPage/MyErrorPage.aspx");
  }
Web.config中
    <customErrors mode="On"/>
    <authentication mode="Windows"/>
注:(Response.Redirect语句在任何情况下都会产生ThreadAbortException异常,但不捕获该异常并不会引起程序中止。如果不设置mode="On",在Application_Error事件会捕获它的异常,中并又回到该过程本身,所以会引起死循环。

Response.Redirect("~/ErrorPage/MyErrorPage.aspx",false);这样写的话,mode="On",应该不用设)

原文地址:https://www.cnblogs.com/cuihongyu3503319/p/767399.html