在web.config中配置出现错误转到error.aspx在error.aspx中用Server.GetLastError,为什么取不到错误信息?error.aspx:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Exception ex = Server.GetLastError(); if (ex != null)
{
Response.Write(ex.Message + "\r\n" + ex.Source);
}
}ex始终为null 为什么???

解决方案 »

  1.   

    只有在错误发生的时候才能触发,你是错误发生的时候直接导向错误页面。当然是现在的结果了。。你可以在GLOBA.ascx.cs中处理,把错误信息传到error.aspx页面再行显示。。
    protected void Application_Error(Object sender, EventArgs e)
    {
      Exception Error = Server.GetLastError();
      if (Error != null)
      {
        Server.Transfer(this.Request.ApplicationPath + "\\Error.aspx?Error=" + Error.InnerException.Message);
      }
    }
      

  2.   

    在Application_Error中取到的还是null处理Page.Error事件,取到了错误信息谢了