1

I have a string coming from an ASP page, and I'm trying to URL decode it and display it in an ASP.Net page.

string str = @"%A0%A01stk.+%D8repynt+%3Cbr%3E%A0%A01stk.+Slipsn%E5l+%3Cbr%3E%3Cp%3E+Total+pris%3A+300";

If you look at %D8 it should be translated to the Norwegian character Ø when run through HttpUtility.UrlDecode. But it is not. Depending on what conversion I'm attempting it becomes different things, but never Ø. %E5 should become å.

Here is some conversion code I've been trying out:

public static string Convert(string text)
{
 text = HttpUtility.UrlDecode(text);
 var isoEncoder = System.Text.Encoding.GetEncoding("ISO-8859-1");
 var utf8Encoder = new UTF8Encoding();
 byte[] txtBytes = isoEncoder.GetBytes(text);
 byte[] convertedBytes = System.Text.Encoding.Convert(isoEncoder, System.Text.Encoding.UTF8, txtBytes);
 return utf8Encoder.GetString(convertedBytes);
}

According to Wikipedia article on Ø:
On Microsoft Windows, using the "United States-International" keyboard setting, it can be typed by holding down the Alt-Gr key and pressing "L". It can also be typed under any keyboard setting by holding down the [Alt] key while typing 0216 or 0248 on the numeric keypad, provided the system uses code page 1252 as system default. (Code page 1252 is a superset of ISO 8859-1, and 216 and 248 are the decimal equivalents of hexadecimal D8 and F8.)

This seems to indicate that the input string is correctly formatted (%D8 = Ø).

asked Sep 6, 2011 at 11:08
2
  • What is the character set for the ASP.NET page? Commented Sep 6, 2011 at 11:11
  • The response from server says Content-Type: text/html; charset=utf-8. I also forgot to mention I can't make any major changes to web.config because its a common config file for lots of pages. Commented Sep 6, 2011 at 11:22

1 Answer 1

1
 string str = @"%A0%A01stk.+%D8repynt+%3Cbr%3E%A0%A01stk.+Slipsn%E5l+%3Cbr%3E%3Cp%3E+Total+pris%3A+300";
 string decoded = System.Web.HttpUtility.UrlDecode(str, System.Text.Encoding.GetEncoding("ISO-8859-1"))
answered Sep 6, 2011 at 11:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.