I have a random generated string that I need to put it in a URL, so I encode it like this:
var encodedToken = System.Web.HttpUtility.UrlEncode(token, System.Text.Encoding.UTF8);
In an ASP.NET action method, I receive this token and decode it:
var token = System.Web.HttpUtility.UrlDecode(encodedToken, System.Text.Encoding.UTF8);
but these tokens are not the same. For example the ab+cd
string would encode to ab%2bcd
and decoding the result would give me the ab cd
string (the plus character changed to whitespace).
So far I have only noticed the +
character problem, there may be others.
How can I solve this issue?