Server.URLEncode diffrences in asp and vb.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Trying to urlencode this string:

»ÃÃŒŠ˜ªŒÂ›h^aYh

in vb.net (using either HttpUtility.UrlEncode(strEncrypted, encoding.UTF8)
orServer.UrlEncode) I get:
%c2%90%c2%bb%c3%81%c3%8f%7f%c5%92%c5%a0%cb%9c%c2%aa%c5%92%c2%9d%e2%80%bah%5eaYh

in ASP script (using Server.URLEncode) I get:
%90%BB%C1%CF%7F%8C%8A%98%AA%8C%9D%9Bh%5EaYh

Any idea why?

Thanks,
Mark
 
Well, This ended up working:
System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(strEncrypted))

Still odd that you have to jump though those hoops to get it to do what ASP
does.

Any insight would be appreciated.

Thanks,
Mark
 
Hello Mark,
Trying to urlencode this string:

»ÁÏŒŠ˜ªŒ›h^aYh

Hm... ;-)
in vb.net (using either HttpUtility.UrlEncode(strEncrypted,
encoding.UTF8) orServer.UrlEncode) I get:
%c2%90%c2%bb%c3%81%c3%8f%7f%c5%92%c5%a0%cb%9c%c2%aa%c5%92%c2%9d%e2%80%
bah%5eaYh

in ASP script (using Server.URLEncode) I get:
%90%BB%C1%CF%7F%8C%8A%98%AA%8C%9D%9Bh%5EaYh
Any idea why?

ASP uses a different character encoding -- that's not UTF-8, but some 8 bit
encoding like ISO Latin 1 or Windos-1252.

Cheers,
 
Thanks for the reply.

When I tell ASP to force encoding as so:
Session.CodePage = 65001
Response.CharSet = "utf-8"

I get a totally diffrent result then the previous 2

I looked for the two encoding methods you mentioned in System.Text.Encoding
but don't see them as options. I will google them and see what I can find.

Mark
 
That did the trick. I couldn't find anything to do the conversion so I
wipped up this:
Public Function ASPURLEncode(ByVal StringToEncode As String) As String

Dim TempAns As New StringBuilder
Dim CurChr As Integer = 1
Do Until CurChr - 1 = Len(StringToEncode)
Select Case Asc(Mid(StringToEncode, CurChr, 1))
Case 48 To 57, 65 To 90, 97 To 122
TempAns.Append(Mid(StringToEncode, CurChr, 1))
Case 32
TempAns.Append("%" & Hex(32))
Case Else
TempAns.Append("%")
TempAns.Append(Hex(Asc(Mid(StringToEncode, CurChr, 1))))
End Select
CurChr = CurChr + 1
Loop
ASPURLEncode = TempAns.ToString
End Function

And now I have a match.

Thanks for your help.

Mark
 
Hello Mark,
Thanks for the reply.

When I tell ASP to force encoding as so:
Session.CodePage = 65001
Response.CharSet = "utf-8"
I get a totally diffrent result then the previous 2

I'm no old school ASP guy, but I'd guess that none of these properties affect
URL encoding performed by ASP.
I looked for the two encoding methods you mentioned in
System.Text.Encoding but don't see them as options. I will google
them and see what I can find.

In ASP.NET, you can use System.Web.HttpUtility.UrlEncode(String, Encoding)
to URL encode a string using any System.Text.Encoding.

Cheers,
 
I wrote that function but if I can, I would rather do it within the framework
..

"ISO Latin 1" isn't an option in system.text.encoding.

Is there some other encoding method in the framework?

Thanks,
Mark
 
Hello Mark,
I wrote that function but if I can, I would rather do it within the
framework .

"ISO Latin 1" isn't an option in system.text.encoding.

Is there some other encoding method in the framework?

ISO Latin 1 is an alias for ISO-8859-1. You can create an instance either
by name

Encoding latin1 = Encoding.GetEncoding("ISO-8859-1");

or by its Windows code page number

Encoding latin1 = Encoding.GetEncoding(28591);

Cheers,
 
Back
Top