我在我的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)
Run Code Online (Sandbox Code Playgroud)
实际源代码: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;
}
Run Code Online (Sandbox Code Playgroud)
因此.Net不允许从危险的表单数据创建新的NameValueCollection .我的应用程序中有很多Html编辑器,我希望ELMAH能够在任何情况下记录错误.
我能做什么?
不幸的是,这是由于 ASP.NET 4.0 引入的重大更改造成的。现在的解决方法是通过将以下内容添加到配置中来要求 ASP.NET 恢复到旧的行为:
<httpRuntime requestValidationMode="2.0" />
Run Code Online (Sandbox Code Playgroud)
有关更完整的讨论,请参阅ELMAH 项目网站上的问题 #217。
| 归档时间: |
|
| 查看次数: |
379 次 |
| 最近记录: |