Thursday, November 1, 2012

JavaScriptStringEncode : Javascript Compitable encoding


Recently I was facing very interesting issue. and the solution for the issue was introduced in the new updates in framework 4.0.

Generally when we try to render HTML content on page clientside/ by javascript, it gives error of Potential dangerous content error.

There are lot's solutions but have to compromise security of page.
by setting

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
    Inherits="_default" ValidateRequest="false"%>

 But now we have perfect solution which is introduced in .net framework 4.0

HttpUtility.JavaScriptStringEncode Method

URL encoding makes sure that all browsers correctly encodes text in URL strings. Few Characters such as a question mark (?), ampersand (&), slash (/), and spaces might be truncated or corrupted by some browsers. Therefore, these characters must be encoded in a elements or in query strings where the strings can be re-sent by a browser in a request string.

refer following  MSDN link

Hope this helps