asp.net mvc 2 ,.net 4.0 “检测到有潜在危险的 Request.Form 值”的解决方法

1.在页面aspx中

<%@ Page ValidateRequest="false" >

2.在controller中action添加。

[ValidateInput(false)]

public ActionResult Edit()

{

this.ValidateRequest = false;

retrun View();

}

3.在网站web.config

<system.web>

<httpRuntime requestValidationMode="2.0" />

</system.web>

在.net 4.0 环境下请求验证范围扩大到所有请求。从BeginRequest阶段就开始HttpRequest,不仅仅是页面文件(.aspx),还包含webservice以及http Handlers。