如何避免Htt的prequestValidationException在ASP.NET MVC渲染导致异常相同的看法 [英] How to avoid HttpRequestValidationException in ASP.NET MVC rendering the same view which caused the exception

查看:219
本文介绍了如何避免Htt的prequestValidationException在ASP.NET MVC渲染导致异常相同的看法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何验证(或干净的),用户输入的ASP.NET MVC这样的Htt的prequestValidationException不会考虑提交的值抛出。例如,文本输入,如果用户输入< BR /> ,这将导致异常和死亡的黄色屏幕将显示。我不希望出现这种情况。我想用装有提交相同的值的控制pferably捕获异常,并做出明显的一个用户友好的错误在目前看来,$ P $。

I just want to know how to validate (or clean) user input in ASP.NET MVC so that an HttpRequestValidationException will not be thrown regardless of the values submitted. For example, with a text input, if the user inputs <BR/>, it will cause an exception and the Yellow Screen of Death will be shown. I don't want that. I want to catch the exception and to make visible an user friendly error in the current view, preferably with the controls loaded with the same values submitted.

我发现这个<一href="http://www.romsteady.net/blog/2007/06/how-to-catch-htt$p$pquestvalidationexcep.html">http://www.romsteady.net/blog/2007/06/how-to-catch-htt$p$pquestvalidationexcep.html,但它是没有用我的目的。另外,我发现这个<一href="http://msdn.microsoft.com/en-us/library/aa973813.aspx">http://msdn.microsoft.com/en-us/library/aa973813.aspx并试图把一个模型绑定内,但我不能让工作。

I have found this http://www.romsteady.net/blog/2007/06/how-to-catch-httprequestvalidationexcep.html, but it is useless for my purpose. Also, I have found this http://msdn.microsoft.com/en-us/library/aa973813.aspx and tried to put inside a model binder but I couldn't make to work.

推荐答案

使用ASP.NET MVC的(居委,在写这个的时候)的最新版本,你可以把一个属性上的任何控制器类或你的操作方法,例如:

With the latest version of ASP.NET MVC (the RC, at the time of writing this) you can just put an attribute on either your controller class or your action method, e.g.:

[ValidateInput(false)]
public ActionResult create()
{
    // ...method body
}

该ValidateInputAttribute是在System.Web.Mvc。

The ValidateInputAttribute is in System.Web.Mvc.

不过,正如其他人所说,你就那么必须执行自己手动输入验证或清洁。

But as others have said, you do then have to perform your own manual input validation or cleaning.

使用MVC 3,你还必须确保这是你的web.config:&LT;的System.Web&GT;&LT;的httpRuntime requestValidationMode =2.0/></system.web>

Using MVC 3, you must also ensure this is in your Web.config: <system.web><httpRuntime requestValidationMode="2.0" /></system.web>

这篇关于如何避免Htt的prequestValidationException在ASP.NET MVC渲染导致异常相同的看法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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