我无法关闭请求验证的ASP.NET MVC控制器 [英] I can't turn off Request Validation for an ASP.NET MVC Controller

查看:250
本文介绍了我无法关闭请求验证的ASP.NET MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图关闭请求验证所有的操作方法在控制器通过执行此操作:

I am trying to turn off Request Validation for all action methods in a controller by doing this:

[ValidateInput(false)]
public class MyController : Controller
{
    ...

我使用的参考表示,这是可能的,告诉我做这种方式,但由于某种原因它不工作。

The reference I am using says this is possible and tells me to do it this way, but for some reason it's not working.

如果我提交任何HTML通过文本框(甚至一个简单的< b取代标记),我得到的错误:

If I submit any html (even a simple <b> tag) through a text box, I get the error:

一个潜在危险的Request.Form值从客户端检测到(文=&LT; B&gt;中)。

A potentially dangerous Request.Form value was detected from the client (text=<b>").

它也没有工作通过附加属性的单个方法。

It's also not working by attaching the attribute to an individual method.

如何禁用请求验证控制器?

How can I disable Request Validation for a controller?

我工作在VS2008内置的测试服务器。

I am working in VS2008 built in test server.

推荐答案

我测试了我的机器上,在类的定义和操作方法两者,它在这两种情况下为我工作。你确定你的看法线与你的方法/控制器?你把属性的GET方法或POST方法?

I tested it on my machine, on both the class definition and the action method, and it worked for me in both cases. Are you sure your view lines up with your method/controller? Are you putting the attribute on the GET method or the POST method?

[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]   
public ActionResult MyAction (int id, string content) {   
    // ...   
}

这篇关于我无法关闭请求验证的ASP.NET MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆