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:
最初,在升级到ASP之后。Net 4.0,我收到了请求验证错误,我想停止。我可以通过设置httpruntime来使用请求验证的2.0来实现这一点,正如这里提到的:
Request Validation - ASP.NET MVC 2
请求验证- ASP。NET MVC 2
However, I also need to allow longer querystrings, and want to make use of the 4.0 maxQueryStringLength attribute.
但是,我还需要允许更长的查询字符串,并希望使用4.0 maxQueryStringLength属性。
However, this attribute has no effect when 2.0 request validation is turned on.
但是,当打开2.0请求验证时,该属性没有任何影响。
Does anyone know how I can get both to work together? Or is this just not possible?
有人知道我怎么能让他们一起工作吗?或者这是不可能的?
Thanks!
谢谢!
1 个解决方案
#1
2
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:
我有一个似乎行得通的答案……这是一个创建自己的RequestValidator的例子,它允许通过对应用程序代码的所有请求,如下所示:
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...
只要应用程序能够找到它(例如在bin文件夹或GAC中),您就可以覆盖默认的validator…
<httpRuntime requestValidationType="RequestValidators.ValidateAllRequests, RequestValidators" maxQueryStringLength="2048" />
#1
2
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:
我有一个似乎行得通的答案……这是一个创建自己的RequestValidator的例子,它允许通过对应用程序代码的所有请求,如下所示:
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...
只要应用程序能够找到它(例如在bin文件夹或GAC中),您就可以覆盖默认的validator…
<httpRuntime requestValidationType="RequestValidators.ValidateAllRequests, RequestValidators" maxQueryStringLength="2048" />