tags:

views:

27

answers:

1

Initially, after upgrading to ASP.Net 4.0, I was receiving request validation errors, which I wanted to stop. I was able to do this by setting the httpruntime to use 2.0 of the request validation, as mentioned here:

http://stackoverflow.com/questions/1648386/request-validation-asp-net-mvc-2

However, I also need to allow longer querystrings, and want to make use of the 4.0 maxQueryStringLength attribute.

However, this attribute has no effect when 2.0 request validation is turned on.

Does anyone know how I can get both to work together? Or is this just not possible?

Thanks!

+1  A: 

I have an answer that seems to work... it's a case of creating one's own RequestValidator that allows through all requests to the application code, like so:

public class ValidateAllRequests: RequestValidator
{
    protected override bool IsValidRequestString(System.Web.HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
    {
        validationFailureIndex = -1;
        return true;
    }
}

So long as it can be found by the application (i.e. in the bin folder or GAC), you can override the default validator...

<httpRuntime requestValidationType="RequestValidators.ValidateAllRequests, RequestValidators" maxQueryStringLength="2048" />
Mark