Javascript Encode on server side - Medium Trust Environment
It happens from time to time I have to get rid of those funky apostrophe in my server/javascript code. To do such kind of things I was using Microsoft Anti-Cross Site Scripting Library. By simply calling:
public static string JavaSriptEncode(this string text) {
return Microsoft.Security.Application.AntiXss.JavaScriptEncode(text, false);
}
Unfortunately, It doesn’t work in Medium trust environment - btw, why the hell i get stingy clients. After some time digging all over internet and trying to write it by myself I accidentally found a thing that I never believed to be there. Well, ladies and gentleman, since .NET 4.0 HttpUtility has a new static function called… JavaScriptStringEncode
public static string JavaSriptEncode(this string text) {
return HttpUtility.JavaScriptStringEncode(text);
}
Uff!…