【问题标题】:track error on defaultRedirect?defaultRedirect 上的跟踪错误?
【发布时间】:2010-08-28 08:43:49
【问题描述】:

我已经在我的 web.config 中添加了这个:

<customErrors mode="RemoteOnly" defaultRedirect="~/Site/Statics/Eroare.aspx">
          <error statusCode="404" redirect="~/Site/Index.aspx" />
        </customErrors>

好吧,在 Eroare.aspx 页面上的 Page_Load 方法中,我尝试将导致此重定向的错误打印到我的内部日志,但 Server.GetLastError() 为空...

你知道为什么吗?或任何其他解决方案来获得异常?

谢谢。

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    关键是在Global.asax文件中触发错误

        protected void Application_Error(object sender, EventArgs e)
    {
        Exception objErr = Server.GetLastError().GetBaseException();
        string err =    "Error Caught in Application_Error event\n" +
                "Error in: " + Request.Url.ToString() +
                "\nError Message:" + objErr.Message.ToString() + 
                "\nStack Trace:" + objErr.StackTrace.ToString();
        EventLog.WriteEntry("Sample_WebApp",err,EventLogEntryType.Error);
        //Server.ClearError();
        //additional actions...
    } 
    

    更多信息:http://support.microsoft.com/kb/306355

    【讨论】:

      猜你喜欢
      • 2013-01-02
      • 1970-01-01
      • 2015-03-15
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多