What is the .Net equivalent of jscript escape/unescape?

Discussion in 'ASP .Net' started by =?Utf-8?B?SGFycnkgS2Vjaw==?=, Mar 9, 2005.

  1. Is there a set of methods in the .Net framework that do the same thing as the
    jscript functions escape and unescape?

    I get very close with HttpUtility.UrlEncodeUnicode, but it puts "+" for
    spaces instead of "%20". Uri.EscapeString seems to create the correct escape
    string, but there is no unescape. The function is not public anyway, so I
    probably shouldn't use it.

    I need a way to escape text on the client, and then unescape it on the
    server, and then escape it on the server, and unescape it out on the client.
    How can I do this? Thanks.
    =?Utf-8?B?SGFycnkgS2Vjaw==?=, Mar 9, 2005
    #1
    1. Advertising

  2. Hello,
    Because UrlEncode gets very close, I wrote my own methods that just wraps
    that and adds some extra functionality (like replacing the apostrophe ' to
    avoid cross-site-scripting warnings).

    I provide sample code and charts of what UrlEncode escapes at this blog entry:
    http://timstall.dotnetdevelopersjournal.com/read/1092094.htm

    For example:

    public static string UrlFullEncode(string strUrl)
    {
    if (strUrl == null)
    return "";
    strUrl = System.Web.HttpUtility.UrlEncode(strUrl);
    return strUrl.Replace("'",_strApostropheEncoding);
    }
    private const string _strApostropheEncoding = "%27";

    public static string UrlFullDecode(string strUrl)
    {
    if (strUrl == null)
    return "";
    strUrl = strUrl.Replace(_strApostropheEncoding,"'");
    return System.Web.HttpUtility.UrlDecode(strUrl);
    }



    "Harry Keck" wrote:

    > Is there a set of methods in the .Net framework that do the same thing as the
    > jscript functions escape and unescape?
    >
    > I get very close with HttpUtility.UrlEncodeUnicode, but it puts "+" for
    > spaces instead of "%20". Uri.EscapeString seems to create the correct escape
    > string, but there is no unescape. The function is not public anyway, so I
    > probably shouldn't use it.
    >
    > I need a way to escape text on the client, and then unescape it on the
    > server, and then escape it on the server, and unescape it out on the client.
    > How can I do this? Thanks.
    =?Utf-8?B?VGltIFN0YWxs?=, Mar 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,248
    Jon Maz
    Sep 9, 2004
  2. NetKev
    Replies:
    1
    Views:
    4,296
    Owen Jacobson
    Mar 4, 2008
  3. Tony Augustine
    Replies:
    0
    Views:
    339
    Tony Augustine
    Jul 22, 2010
  4. Philipp

    Escape/ Unescape HTML?

    Philipp, Dec 20, 2007, in forum: Javascript
    Replies:
    2
    Views:
    233
    Thomas 'PointedEars' Lahn
    Dec 21, 2007
  5. RK
    Replies:
    1
    Views:
    130
    Gabriel Gilini
    Nov 12, 2008
Loading...

Share This Page