gpt4 book ai didi

asp.net 4 自定义请求验证器似乎不起作用

转载 作者:行者123 更新时间:2023-12-02 17:45:50 27 4
gpt4 key购买 nike

我正在按照 http://msdn.microsoft.com/en-us/library/system.web.util.requestvalidator.aspx 的示例进行操作但它似乎不起作用,我仍然收到错误。这是我的类(class)以及我如何将其添加到 webconfig

我的网络配置:

     <httpRuntime requestValidationType="CustomRequestValidation"/>

我的类(class):

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=@"<,>,*,%,&,:,\,?")]公共(public)字符串RequestPathInvalidCharacters { 获取;放; }

关于asp.net 4 自定义请求验证器似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3795256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com