【问题标题】:Errors not recorded in ELMAHELMAH 中未记录的错误
【发布时间】:2013-06-12 11:32:51
【问题描述】:

我在我的 mvc 项目中使用 ELMAH 来记录错误。我意识到有时没有记录错误。因此,我将语句包装在 try..catch 中并调用 ErrorSignal.FromCurrentContext().Raise(ex);,但没有针对该特定错误再次记录任何内容。所以我尝试进入ELMAH源代码(使用Reflector VS addin)。我在 elmah 中看到了这个异常:

 A potentially dangerous Request.Form value was detected from the client (Text="<br>").
 StackTrace:    at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)

实际源代码:this._form = CopyCollection(request.Form); in public Error(System.Exception e, HttpContext context) in Error.cs。和 CopyCollection 方法:

private static NameValueCollection CopyCollection(NameValueCollection collection)
{
    if ((collection != null) && (collection.Count != 0))
    {
        return new NameValueCollection(collection);
    }
    return null;
}

所以 .Net 不允许从 危险 表单数据创建新的 NameValueCollection。我的应用程序中有很多 Html 编辑器,我希望 ELMAH 在任何情况下都能记录错误。

我能做什么?

【问题讨论】:

    标签: asp.net-mvc elmah


    【解决方案1】:

    很遗憾,this is due to a breaking change introduced by ASP.NET 4.0。现在的解决方法是要求 ASP.NET 通过将以下内容添加到您的配置中来恢复旧行为:

    <httpRuntime requestValidationMode="2.0" />
    

    如需更完整的讨论,请参阅ELMAH project site 上的issue #217

    【讨论】:

    • 我注意到问题 #217 已于 2012 年 9 月修复。是否有发布新版本 Elmah 的计划?
    • @AtifAziz PLUSONE!请推到nuget?这是很久以前修补的...如果问题是需要 framework>=4,那么也许有一个 v4 nuget 包?
    猜你喜欢
    • 1970-01-01
    • 2010-10-20
    • 2019-04-13
    • 2011-03-01
    • 2012-03-04
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    相关资源
    最近更新 更多