我们在ASP.net 4.0 中使用URL导向后, 我们在访问类似如下的地址一个面试题!********/,就会报错误:
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)
这是因为上述地址中有*这个特殊字符存在。
如果你想不让ASP.net 替你拦截这些特殊字符,你需要设置如下Web.config的节:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<httpRuntime requestPathInvalidCharacters="" />
</system.web>
</configuration>
注意其中的requestPathInvalidCharacters
即,不设置这个属性,默认就是如下设置:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,:,&,\" />
</system.web>
</configuration>
如果你想这些字符全部不受限制,就应该设置 requestPathInvalidCharacters="" , 如果是部分字符受限制,部分字符不受限制,就需要在 requestPathInvalidCharacters
参考资料:
Experiments in Wackiness: Allowing percents, angle-brackets, and other naughty things in the ASP.NET/IIS Request URL
http://www.budoou.com/article/981320/