gpt4 book ai didi

asp.net-mvc - ELMAH 中未记录的错误

转载 作者:行者123 更新时间:2023-12-04 20:46:34 24 4
gpt4 key购买 nike

我在我的 mvc 项目中使用 ELMAH 来记录错误。我意识到有时错误没有记录。所以我将语句包裹在 try..catch 中并调用 ErrorSignal.FromCurrentContext().Raise(ex);但没有再次记录该特定错误。所以我尝试进入 ELMAH 源代码(使用 Reflector VS 插件)。我在 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);public Error(System.Exception e, HttpContext context)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 在任何情况下都能记录错误。

我能做什么?

最佳答案

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

<httpRuntime requestValidationMode="2.0" />

有关更完整的讨论,请参阅 issue #217ELMAH project site .

关于asp.net-mvc - ELMAH 中未记录的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17131836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com