質問

I'm using ELMAH in my mvc project to record errors. I realised that sometimes errors not recorded. So I wrapped the statements in try..catch and called ErrorSignal.FromCurrentContext().Raise(ex); but nothing get recorded again for that specific error. So I tried to step into ELMAH source code (using Reflector VS addin). And I saw this exception in 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)

Actual source code: this._form = CopyCollection(request.Form); in public Error(System.Exception e, HttpContext context) in Error.cs. and CopyCollection method:

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

So .Net does not allow creating new NameValueCollection from dangerous form data. I have a lot of Html editors in my application and I want ELMAH to record errors in any situation.

What can I do?

役に立ちましたか?

解決

Unfortunately, this is due to a breaking change introduced by ASP.NET 4.0. A workaround right now would be to ask ASP.NET to revert back to the older behavior by adding the following to your configuration:

<httpRuntime requestValidationMode="2.0" />

For a more complete discussion, see issue #217 on the ELMAH project site.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top