开发者

ValidateRequest = False but in action it's still True and ignored that?

i want disable RequestValidation on particular view in ASP.NET MVC 2.0 RTM. so i added some necessary to view Page directive section as below:

<%@ Page ValidateRequest="false" Language="C#" MasterPageFile="Path" Inherits="System.Web.Mvc.ViewPage<Path>" %>
开发者_Go百科

but RequestValidation isn't Disabled! i also added RequestValidation Attribute to related action in controller as below:

[System.Web.Mvc.ValidateInput(false)]
public System.Web.Mvc.ActionResult Create(Model instance)
{
    //Do here something
}

:') but RequestValidation isn't Disabled too!

in last try i set RequestValidation to false in Web.config file as below:

<pages validateRequest="false" />

RequestValidation still isn't turned off!

Why? thank's in advance ;)


If you are using asp.net 4.0 the validate request feature behavior has been changed from version 2.0. Check out the breaking changes document here. If this is the case you can resolve the problems by setting the request validation behavior back to the 2.0 in the web.config like this:

<httpRuntime requestValidationMode="2.0" />


just add

[ValidateInput(false)]

in your controller function but don't forget to encode the value to prevent harmful code

    [ValidateInput(false)]
    public string Browse(string test)
    {
        string message = HttpUtility.HtmlEncode("Value = " + test);
        return message;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜