Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I stop .net 4.0 from encoding single quotes?

After switching to .net 4.0, some javascript code from a third party gridview crashes. It has got something to do with HtmlEncode and UrlEncode now encode single quotation marks

So before some code on the page was inserted like this: DataItem.GetMember('Id').Value

and now its like this: DataItem.GetMember('Id').Value

The gridview does an eval on that line, and crashes with a syntax error now. I can't change the javascript code in that gridview.

Is there anyway to solve this, without going backwards like this?

<pages controlRenderingCompatibilityVersion="3.5" /> 

EDIT: the pages controlRenderingCompatiblityVersion doesn't fix this also. Single quotes are still encoded.

like image 995
Erik Dekker Avatar asked Jun 15 '12 13:06

Erik Dekker


1 Answers

From what I've read, it's a security feature and Microsoft is mum about changing it. The only work-around I've seen is you will need to create a custom encoder class. You can turn-off attribute encoding using this:

public class HtmlAttributeEncodingQuote : System.Web.Util.HttpEncoder
{
    protected override void HtmlAttributeEncode(string value, System.IO.TextWriter output)
    {
        output.Write(value);
    }
}

Then add this to web.config under system.web:

<httpRuntime encoderType="HtmlAttributeEncodingQuote"/>
like image 153
Josh Avatar answered Oct 16 '22 13:10

Josh