请求验证 - ASP.NET MVC 2 [英] Request Validation - ASP.NET MVC 2
问题描述
ASP.NET MVC 2 的请求验证是否已更改,更准确地说,未验证?
Has request validation changed for ASP.NET MVC 2, more precisely, not validating?
我做了以下事情:
Web.configs(在 App 目录和 Views 目录中)
Web.configs (in App directory and Views directory)
<pages
validateRequest="false"
控制器/动作属性
[ValidateInput(false)]
在@Page 视图指令中
In @Page View Directive
ValidateRequest="false"
页面仍然得到验证,但在发布 HTML 内容时抛出异常.
The page still gets validated an exception is thrown when HTML content is posted.
更新
创建了一个新的 ASP.NET MVC 2 应用程序,我将主控制器的索引修改为这个
Created a new ASP.NET MVC 2 Application and I modified the Home Controller's Index to this
[ValidateInput(false)]
public ActionResult Index(string InputText)
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
和我的查看页面
<% using(Html.BeginForm()){ %>
<%= Html.TextBox("InputText") %>
<input type="submit" />
<% } %>
还是同样的问题,抛出异常.
And still the same issue, an exception is thrown.
推荐答案
下次我应该更仔细地阅读错误:
I should read the error more carefully next time:
要允许页面覆盖应用程序请求验证设置,在配置部分设置 requestValidationMode="2.0".设置此值后,您可以通过以下方式禁用请求验证设置validateRequest="false"
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"
我把它放在应用程序的 web.config 中
I put this in the application's web.config
<system.web>
<httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters="" />
</system.web>
它奏效了.
更新:
我运行的是 ASP.NET 4 这就是为什么 :P
I was running ASP.NET 4 thats why :P
这篇关于请求验证 - ASP.NET MVC 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!