2

I have this in my querystring - sug_zehut=ז
(ז is a Hebrew letter)

Although I'm well aware that this is bad practice, I have to receive it like so in my query string (not my code..)

When I write it to a hidden I get sug_zehut=%EF%BF%BD as a part of the querystring, and when I try to put it in a string and put that in a hidden, I get � (I found here that those two are the same).

Anyhow, the question is - How do I get the value ז to my variable?

(I'm using .net version 4)

Thanks.

Oren A
  • 5,870
  • 6
  • 43
  • 64
  • May this help you: http://stackoverflow.com/questions/2742852/unicode-characters-in-urls – Aki Nov 17 '14 at 10:11
  • _"When I write it to a hidden"_ - You really should post some code. Are you working between Unicode in JavaScript and UTF-8? There are built in ways of handling this `encodeURIComponent` but it depends on from where to where. If you want an answer, post a snippet of code which reproduces the problem. – doog abides Nov 22 '14 at 06:21

2 Answers2

2

%EF%BF%BD is the code of � sumbol. That's mean your server don't know this character because of you sent symbol in one encoding and try get it as UTF-8.

Try to set up utf-8 encoding in every place (at least for testing of the problem):

  1. In web.config http://msdn.microsoft.com/en-us/library/ydkak5b9(v=vs.71).aspx
  2. In the page <meta charset="utf-8"> vs <meta http-equiv="Content-Type">
  3. Change real file encoding if you directly set up your symbol (.cs, .cshtml, .aspx, .js, ...)

If it's not working that please tell me how do you get this url and navigate on it?

Community
  • 1
  • 1
  • It also looks like , as OP is talking about hidden field , browser is also needs to be set to UTF-8 Encoding I guess , right ? – Vishal Sharma Nov 22 '14 at 10:16
0

Here's a small function to convert your character to an HTML encoded version (&#1494; in this case). HtmlEncode won't do it for you in most versions of .net, unfortunately.

private static string UnicodeConvertChar(char input)
{
    if (input > 159)
    {
        return "&#" + ((int)input).ToString() + ";";
    }
    else
    {
        return input.ToString();
    }
}

You can convert it before setting it in your hidden field, and then when you get it back, you can simply read it by using HttpUtility.HtmlDecode.

Here's a dotnetfiddle for you to play around with it: https://dotnetfiddle.net/jbDY0V

jlee-tessik
  • 1,510
  • 12
  • 16