views:

483

answers:

1

I get this error when i post from TinyMCE in an asp.net mvc view

Error: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted

from googling, it says to just add a validateRequest in the Page directive at the top which i did but i STILL get this error. As you can see, below is my code in the view:

<%@ Page validateRequest="false" Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
+3  A: 

Use the decorator [ValidateInput(false)].

You will then want to write a HTMLEncode method to make it safe.

Let me know if you want me to post the one I use.

Added the Encode I use

    public static class StringHelpers
{
    public static string HtmlEncode(this string value)
    {
        if (!string.IsNullOrEmpty(value))
        {
            value = value.Replace("<", "&lt;");
            value = value.Replace(">", "&gt;");
            value = value.Replace("'", "&apos;");
            value = value.Replace(@"""", "&quot;");
        }
        return value;
    }

    public static string HtmlDecode(this string value)
    {
        if (!string.IsNullOrEmpty(value))
        {
            value = value.Replace("&lt;", "<");
            value = value.Replace("&gt;", ">");
            value = value.Replace("&apos;", "'");
            value = value.Replace("&quot;", @"""");
        }

        return value;
    }
}
griegs
if you can post that would be great
ooo
thanks.. that worked great. is there anyway to prepoulate the textarea from an existing html page
ooo
Don't quite understand what you mean [me]. Are you talking about screen scraping here or...
griegs
Worth noting two things if using VS2010 and ASP.NET MVC2. First of all, you need to put <httpRuntime requestValidationMode="2.0" /> within <system.web> in your web.config file for the [ValidateInput(false)] attribute to work. Secondly, the above encoder is far too naive to be reliable.
Ant