Can I stop .net 4.0 from encoding single quotes?

After migrating to .net 4.0, some javascript codes from a third-party gridview crash. It has something to do with HtmlEncode and UrlEncode now encode single quotes

So, before any code on the page was inserted as follows: DataItem.GetMember('Id').Value

and now it’s something like this: DataItem.GetMember('Id').Value

gridview does eval on this line and now fails with a syntax error. I cannot change javascript code in this gridview.

Is there a way to solve this problem without going back?

 <pages controlRenderingCompatibilityVersion="3.5" /> 

EDIT: controlRenderingCompatiblityVersion pages also do not fix this. Single quotes are still encoded.

+7
source share
1 answer

From what I read, this is a security feature, and Microsoft is my mom about changing it. The only thing I saw was to create my own encoder class. You can disable attribute encoding with 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"/> 
+1
source

All Articles