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

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

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 它是一个以逗号分隔的无效字符列表。不设置它时,它默认的无效字符集(以,分割)是后面7个:<,>,*,%,&,:,/

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

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值