HttpRequestValidationexception on Asp.Net MVC

Posted by elranu on Stack Overflow See other posts from Stack Overflow or by elranu
Published on 2012-06-11T16:31:48Z Indexed on 2012/06/11 16:40 UTC
Read the original article Hit count: 266

Filed under:
|

I’m getting an HttpRequestValidationexception with this error message:

“A potentially dangerous Request.Form value was detected from the client”.

But I have AllowHtml on the property that I’m getting the error. The problem is that later in my code I’m getting the following property to know in witch format I will show my view ControllerContext.HttpContext.Request.Params.AllKeys.Contains("format"). And on this “Param Getter” I’m getting the error.

Let’s say my code is similar to the following:

public class House
{
    [AllowHtml]
    public string Text { get; set; }
    public string Name { get; set; }
}

[HttpPost, ValidateAntiForgeryToken]
public ActionResult CreateTopic(House h)
{
 //business code
 if(ControllerContext.HttpContext.Request.Params.AllKeys.Contains("format"))
 {
    Return view;
 }
 }

How can I solve this? I already try with the ValidateInput(false) attribute on the controller action method. Any idea?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc-3