3

This is my code:

var signature_parameters = new SortedDictionary<string, string>()
{
    { "client_id", client_id },
    { "timestamp", timestamp },
};

var signature_base_string = string.Join("&", signature_parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value)));
Response.Write(signature_base_string);

which prints client_id=2446782×tamp=1291723521

What is ×?

sloth
  • 99,095
  • 21
  • 171
  • 219
markzzz
  • 47,390
  • 120
  • 299
  • 507
  • 1
    use HttpUtility class – Kamlesh Arya Feb 07 '14 at 08:56
  • Please *don't* build urls with `string.Concat` if possible... There are plenty of classes that deal whit Url creation correctly like [ParseQueryString](http://stackoverflow.com/questions/7238190/namevaluecollection-for-editing-query-strings/7238228#7238228) or maybe `Url.Action` (for MVC)... And maybe see if you can avoid manual creation of HTML with `.Write` .... – Alexei Levenkov Feb 07 '14 at 09:20
  • I don't use .Concat. Can you show me a correct example? – markzzz Feb 07 '14 at 09:28

2 Answers2

12

Your join is putting the text &times into the string which is being encoded into x because &times is a html named special character

It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
owenrumney
  • 1,520
  • 3
  • 18
  • 37
  • It's bit brute force, but I suppose you could use HttpUtility.HtmlDecode http://msdn.microsoft.com/en-us/library/7c5fyk1k(v=vs.110).aspx – owenrumney Feb 07 '14 at 08:57
  • @markzzz You can try to refer to [this answer](http://stackoverflow.com/a/1877016/1180426), even though it's not standard-compliant and might fail if you have multibyte characters. – Patryk Ćwiek Feb 07 '14 at 08:57
  • @owen79 Wouldn't `HtmlEncode`ing the string work just as well? – user247702 Feb 07 '14 at 08:58
1

try this,

var signature_base_string = string.Join("&amp;", signature_parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value)));

Response.Write(signature_base_string);

Or you can use HttpUtility.HtmlEncode to convert string to HTML- encoded string.

var signature_base_string = string.Join("&", signature_parameters.Select(p => string.Format("{0}={1}", p.Key, p.Value)));
Response.Write(HttpUtility.HtmlEncode(signature_base_string));
Jignesh Thakker
  • 3,638
  • 2
  • 28
  • 35