3

I have following URL:

http://localhost:8041/Reforge.aspx?name=Cyan%ECde&realmId=1

notice %EC in the value of name parameter.

%EC = 236 = ì (igrave)

In my action method:

public ActionResult Index(string name, int realmId) {...}

name[4] is a character with code 65533 (0xFFFD). What am I doing wrong?

2
  • Have you tried decoding the name variable? Commented Nov 12, 2010 at 17:18
  • value is decoded for me by framework, I receive name value decoded already. Commented Nov 12, 2010 at 18:32

4 Answers 4

1

This will depend on the globalization element in web.config:

<globalization requestEncoding="iso-8859-1" />

Or if your site is UTF-8

<globalization requestEncoding="utf-8" />

But in this case the url needs to look like name=Cyan%c3%acde. You should always use URL helpers to generate urls so that they are properly encoded.

Sign up to request clarification or add additional context in comments.

8 Comments

I don't generate URL. I give firefox: localhost:8041/Reforge.aspx?name=Cyanìde&realmId=1 and it replaces "ì" with %EC
What happened when you set the requestEncoding in web.config?
@user93422 Interesting. The link in your comment gets translated by Firefox as http://localhost:8041/Reforge.aspx?name=Cyan%C3%ACde&realmId=1 for me
Putting iso-8859-1 (please correct your answer) fixes my original problem. But now it chokes on Г (UNICODE UTF-8 D090) since it (my program) treats it as two ISO-8859-1 characters (D0 and 90). Apparently the problem is that FireFox does encoding inconsistenly - sometimes it uses UTF8 sometimes it uses Latin-1. Any suggestions?
About translation, do you have any other language besides English installed? Could that affect firefox's encoding decision?
|
1

HttpUtility.UrlDecode("%EC") gives that character (65533) as its output.

HttpUtility.UrlEncode("ì") produces "%c3%ac"

How are you generating this %EC? It looks like your encoding isn't working as ASP.NET is expecting

UPDATE

You say that you're just entering http://localhost:8041/Reforge.aspx?name=Cyanìde&realmId=1 into your browser and that it's not encoding correctly. I would suggest that you shouldn't be entering that into your browser in the first place. If you're generating that URL, you need to encode it (so that it renders as <a href="http://localhost:8041/Reforge.aspx?name=Cyan%c3%acde&realmId=1">). Firefox will show this with the ì when hovering over, but will give the encoded version when clicked or copied.

If users are typing arbitrary unicode into a URL, there's not a good way for you to handle that (since they're effectually sending you invalid requests).

3 Comments

Firefox replaces ì with %EC in the URL itself.
You are right, only if URL is entered manually FireFox uses ISO-8859-1 to encode, and only if non-ascii symbol is in query part (path is always encoded in UTF-8).
actually HttpUtility.UrlDecode("%EC") returns 65533 which is a pretty much "error character".
1

I faced a similar problem with url encoding (ì must be encoded as %EC to work) in ASP.NET and js.

If you set <globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1" \> in system.web node, you must use HttpContext.Current.Server.UrlEncode to urlencode \ decode cause in this way you are using globalization settings in web.config.

Before using UrlEncode in current HttpContext I was using HttpUtility.UrlDecode that doesn't use current globalization settings.

Worked for me!

Comments

0

Some things I can find:

HttpServerUtility.UrlDecode(your param)

HttpUtility.UrlDecode(your param)

Server.UrlDecode(your param)

Any of these working for you?

Comments

Your Answer

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.