首页 技术 正文
技术 2022年11月17日
0 收藏 858 点赞 3,878 浏览 1975 个字

昨天安装了VisualStudio 2010 Ultimate,今天把最近的一个项目升级到了4.0下,结果跑了一下,发现关于页面启用 ValidateRequest=”false” 的部份失效。于是把web站点的版本及项目版本都降回原来的版本后,错误就消失了,于是搜索了一下,找到如下资料:

A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$txtCode=”<code></code>”).

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. To allow pages to override application request validation settings, set requestValidationMode=”2.0″ in the configuration section. After setting this value, you can then disable request validation by setting validateRequest=”false” in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. For more information, see http://go.microsoft.com/fwlink/?LinkId=153133.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$txtCode=”<code></code>”).


Version Information: Microsoft .NET Framework Version:4.0.21006; ASP.NET Version:4.0.21006.1

在安装了Visual Studio 2010 Beta2之后,当页面输入框默认情况下输入“<”或者“>”的时候。按照访问策略,这将导致一些安全问题,诸如:跨站脚本攻击(cross-site scripting attack)。而这个问题的更准确描述则是,当你在安装了.NET Framework 4.0以上版本后,当你的应用程序以.NET Framework 4.0为框架版本,你的任意服务器请求,都将被进行服务器请求验证(ValidationRequest),这不仅包括ASP.NET,同时也包括Web Services等各种HTTP请求,不仅仅针对aspx页面,也针对HTTP Handler,HTTP Module等,因为这个验证(Valify)的过程,将会发生在BeginRequest事件之前。

基于以上原理,在ASP.NET之前的版本中,请求验证也是默认开通的,但是发生在页面级(aspx)的,并且只在请求执行的时候生效,因此,在旧的版本中,我们只需要按以下方式配置即可:

在页面级别(aspx中)设置
ValidateRequest=”false”
或者
在全局级别(Web.config中)设置
<configuration>
    <system.web>
        <pages validateRequest=”false”>

但是,以上设置仅对ASP.NET4.0以上有效。在ASP.NET4.0版本上,我们需要更多一行的配置:

在全局级别(Web.config中)设置
<configuration>
    <system.web>
        <httpRuntime requestValidationMode=”2.0″>

这一点其实在发生错误的页面中已经有说明了。在实际使用过程中,不仅如此,而且我发现requestValidationMode只要设置成小于4.0就可以,比如:1.0,2.0,3.0,3.9都是可以的,错误提示中指明用2.0,目的只是说明用ASP.NET 2.0的默认方式进行工作。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898