【问题标题】:ELMAH Filtering Programmatically not workingELMAH过滤以编程方式不起作用
【发布时间】:2009-08-03 22:49:55
【问题描述】:

Elmah 总是发挥作用。如何以编程方式过滤: 这是我的全局文件:

    /// <summary>
    /// Handles the Filtering event of the ErrorLog control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="Elmah.ExceptionFilterEventArgs"/> instance containing the event data.</param>
    public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
    {
        Filter(e);
    }

    /// <summary>
    /// Handles the Filtering event of the ErrorMail control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="Elmah.ExceptionFilterEventArgs"/> instance containing the event data.</param>
    public void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
    {
        Filter(e);
    }

    /// <summary>
    /// Filters the specified e.
    /// </summary>
    /// <param name="e">The <see cref="Elmah.ExceptionFilterEventArgs"/> instance containing the event data.</param>
    private void Filter(ExceptionFilterEventArgs e)
    {
        Exception exception = e.Exception.GetBaseException();
        var httpException = exception as HttpException;

        if (httpException != null && httpException.GetHttpCode() == 404)
        {
            e.Dismiss();
        }

        if (exception is FileNotFoundException ||
            exception is HttpRequestValidationException ||
            exception is ViewStateException ||
            exception is CryptographicException ||
            exception is NodeNullException ||
            exception is SectionNullException ||
            exception is IdentifierNullException ||
            exception is AccessForbiddenException ||
            exception is HttpException)
        {
            e.Dismiss();
        }
    }

    /// <summary>
    /// Handles the Error event of the Application control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Application_Error(Object sender, EventArgs e)
    {
        bool errorObtained = false;
        Exception ex = null;

        try
        {
            Exception rawException = Server.GetLastError();
            if (rawException != null)
            {
                errorObtained = true;
                if (rawException.InnerException != null)
                {
                    ex = rawException.InnerException;
                }
                else
                {
                    ex = rawException;
                }
            }
        }
        catch
        {
        }

        if (errorObtained && ex != null)
        {
            if ((HttpContext.Current != null) && (HttpContext.Current.Request != null))
            {
                if (HttpContext.Current.IsCustomErrorEnabled)
                {
                    Server.Transfer(errorPage, false);
                }
            }
        }
    }

【问题讨论】:

  • 您是否通过设置断点检查过您的 Filter 方法是否被调用?
  • 没有。这就是它不触发的原因
  • 我的 web.config
  • 和 http 模块
  • 请看这个噩梦的答案stackoverflow.com/questions/1224998/…

标签: asp.net asp.net-2.0 elmah


【解决方案1】:

我认为您必须将 HttpModules 命名为:

<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>

使用上面指定的确切名称

【讨论】:

    猜你喜欢
    • 2010-11-15
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多