请求验证 - ASP.NET MVC 2 [英] Request Validation - ASP.NET MVC 2
问题描述
有请求验证改变了ASP.NET MVC 2,更precisely,没有验证?
Has request validation changed for ASP.NET MVC 2, more precisely, not validating?
我做了以下内容:
Web.configs(在应用程序目录,并查看目录)
Web.configs (in App directory and Views directory)
<pages
validateRequest="false"
控制器/ action属性
Controller/Action Attribute
[ValidateInput(false)]
在@Page指令查看
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屋!