A potentially dangerous Request.Path value was detected from the client 异常

我们在A SP.net 4.0 中使用URL导向后, 我们在访问类似如下的地址时 http://wz.csdn.net/ya njinde77/一个面试题!********/ ,就会报错误: 

A potentially dangerous Request.Path value was detected from the client

a t System.Web.HttpRequest.Va lida teInputIfRequiredByConfig()  

a t System.Web.HttpA pplica tion.Va lida teRequestExecutionStep.System.Web.HttpA pplica tion.IExecutionStep.Execute()  

a t System.Web.HttpA pplica tion.ExecuteStep(IExecutionStep step, Boolea n& completedSynchronously)

这是因为上述地址中有*这个特殊字符存在。

如果你想不让A SP.net 替你拦截这些特殊字符,你需要设置如下Web.config的节:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<httpRuntime requestPathInvalidCharacters="" />
</system.web>
</configuration> 

注意其中的requestPa thInva lidCha ra cters 它是一个以逗号分隔的无效字符列表。不设置它时,它默认的无效字符集(以,分割)是后面7个:<,>,*,%,&,:,\

即,不设置这个属性,默认就是如下设置:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,:,&amp;,\" />
</system.web>
</configuration> 


如果你想这些字符全部不受限制,就应该设置 requestPa thInva lidCha ra cters ="" , 如果是部分字符受限制,部分字符不受限制,就需要在 requestPa thInva lidCha ra cters 中设置需要受限制的字符,不受限制的不用设置。

 

参考资料:

Experiments in Wa ckiness: A llowing percents, a ngle-bra ckets, a nd other na ughty things in the A SP.NET/IIS Request URL
http://www.budoou.com/a rticle/981320/

http://blog.joycode.com/ghj/archive/2010/06/29/116007.joy

你可能感兴趣的:(asp.net)