Unescaping ASP vbscript escaped string

V

Vance Kessler

We are trying write a new ASP.NET page to work with an existing
stateless ASP application. The ASP application creates a cookie and
of course stores the cookie values as escaped strings (using the
vbscript escape function). I am have a terrible time 'unescaping'
that string with C# under ASP.NET.

I have tried the following:
HttpUtility.UrlDecode
HttpUtility.HtmlDecode (this should not work but I tried it)
System.Web.HttpContext.Current.Server.UrlDecode
System.Web.HttpContext.Current.Server.HtmlDecode (tried this too)

They all return the same string back or a slightly unescaped version.
Is there something about the way VBScript's escape works that is not
compatible with UrlDecode? Is there something about accessing this
through HttpCookie that changes things? Will I have to write my own
function to decode this or is there some other functions I can access
that will do this?

Thanks
 
E

Eric Lawrence [MSFT]

It should be trivial to write your own function to unescape-- simply walk
the string character by character. If the string contains a % then the next
two characters should be digits. Convert the %xx to a character of value
xx. If the % is followed by a character "u", the next 4 characters are
digits containing a character value.

Note that the VBScript escape function is not the same as URL Encode.
--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
 
V

Vance Kessler

The solution is to use JScript unescape function. Like this:


using Microsoft.JScript;
..
..
..
System.Web.HttpCookie oCookie = Request.Cookies["<NameOfCookieDomain>"];
string sEscapedValue = oCookie.Values["<NameOfCookie>"];
string sValue = Server.UrlDecode(sEscapedValue);
sValue = Microsoft.JScript.GlobalObject.unescape(sValue);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top