[英]asp.net 4 custom request validator doesn't seem to work
我正在關注http://msdn.microsoft.com/en-us/library/system.web.util.requestvalidator.aspx上的示例,但它似乎不起作用,我仍然得到錯誤。 這是我的班級以及如何將其添加到webconfig
我的webconfig:
<httpRuntime requestValidationType="CustomRequestValidation"/>
我的課:
public class CustomRequestValidation : RequestValidator
{
public CustomRequestValidation() { }
protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
{
validationFailureIndex = -1;
if (requestValidationSource == RequestValidationSource.Path)
{
// value "&","=" allowed.
if (value.Contains("&") || value.Contains("="))
{
validationFailureIndex = -1;
return true;
}
else
{
//Leave any further checks to ASP.NET.
return base.IsValidRequestString(context, value, requestValidationSource, collectionKey, out validationFailureIndex);
}
}
else
{
return base.IsValidRequestString(context, value, requestValidationSource, collectionKey, out validationFailureIndex);
}
}
}
錯誤詳情如下:
System.Web.HttpException
A potentially dangerous Request.Path value was detected from the client (=).
System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (:).
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.ValidateRequestExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
我也有這個問題,並將其添加到web.config解決了這個問題。
<httpRuntime requestPathInvalidCharacters="" />
默認情況下,.Net 4.0使用<> *%&:\\拒絕所有請求? 可能導致問題的字符對我來說就像是對我而言。
[ConfigurationProperty(“requestPathInvalidCharacters”,DefaultValue = @“<,>,*,%,&,:,\\,?”)]公共字符串RequestPathInvalidCharacters {get; 組; }
請嘗試在requestValidationType中添加名稱空間
requestValidationType = “CustomControlTest.CustomRequestValidator”
這里CustomControlTest是命名空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.