永远不会调用ASP.NET全局Application_Error事件处理程序

时间:2015-07-16 16:39:09

标签: asp.net web-config global-asax custom-errors

我有一个ASP.NET Web窗体应用程序,它在Globas.asax文件的Application_Error事件处理程序中记录未处理的异常。这一段时间工作正常,但由于未知的变化,它停止了工作。当发生未处理的异常时,永远不会调用该方法。

Web.Config文件中的相关部分如下所示:

 <customErrors mode="Off" />

处理程序方法是:

void Application_Error(object sender, EventArgs e)
{
            Logging.Logger.ServerLog_AddLogEntry(Logging.Logger.ServerLogEntryCategories.Debug, "Unhandled exception caught in global Application_Error(). User: " + Request.RequestContext.HttpContext.User.Identity.Name + ". The details should follow now...");

            // Get the exception object.
            Exception exc = Server.GetLastError();

            if (exc != null && exc is HttpUnhandledException)
                exc = exc.InnerException;
            else
            {
                if (Context != null && Context.AllErrors.Length > 0)
                {
                    string errors = string.Join(Environment.NewLine + "Exception: ", Context.AllErrors.Select(ae => ae.ToString()));
                    exc = new Exception("AllErrors: " + errors);
                }
            }

            if (exc != null)
                Logging.Logger.ServerLog_AddLogEntry(Logging.Logger.ServerLogEntryCategories.Error, "Unhandled exception caught in global Application_Error(). User: " + Request.RequestContext.HttpContext.User.Identity.Name + "." + Environment.NewLine + "Page: " + Request.Url.ToString(), exc);
            else
                Logging.Logger.ServerLog_AddLogEntry(Logging.Logger.ServerLogEntryCategories.Error, "Unhandled exception caught in global Application_Error(). No Exception available. User: " + Request.RequestContext.HttpContext.User.Identity.Name + "." + Environment.NewLine + "Page: " + Request.Url.ToString(), null);

            Server.ClearError();

            Server.Transfer("~/Error.aspx");
}

即使是第一个Logger方法也永远不会被执行。但是,用户确实以某种方式转移到Error.aspx页面。 请注意,此行为仅在实时服务器上发生,但在本地调试时则不会发生。 我已经验证了Web.config和machine.config都没有包含&#34; retail = true&#34;这可以解释这种行为。 有谁知道还有什么可能导致这种情况?

0 个答案:

没有答案
相关问题