In my MVC applciation, sometimes I'm creating my querystring dynamically: once from javascript, and once from c# server code. In javascript, I'm using encodeURIComponent(value)
, and from the c#, I'm using HttpUtility.UrlEncode(value)
method from System.Web
Suppose, I have space in the value
, ex: a q:
encodeURIComponent(value)
returns a%20qHttpUtility.UrlEncode(value)
returns a+q
Space is encoded differently, using these two methods. Is that any reason why is it working this way, different that "it was written like that long time ago and stays untouched" ?
Additionally, suppose I have plus in the value
, ex: a+q
encodeURIComponent(value)
returns a%2BqHttpUtility.UrlEncode(value)
returns a%2bq
The js method returns upper case encoded characters, while c# one returns lower case ones.
What is the best way to cooperate in parallel with these two methods, to make the application behave in coherent way ? Shall I write alternative c# method to imitate the js method behaviour ? I suppose the decoding methods has the same differences. Is there any "correct" way work with these ?