Gopal Biswas Gopal Biswas - 11 months ago 44
ASP.NET (C#) Question

Why we use UrlEncode

I generally use the code

_uri = Server.UrlEncode(_uri);
before any page redirection with parameter values but I don't know the significance of using UrlEncode for this.I want to know the benefit of using UrlEncode.

Answer Source

URLEncode returns a string in which all non-alphanumeric characters other than – (hyphen) _ (underscore), and . (period) have been replaced with a percent (%) sign followed by two hex digits that correspond to the charactor code and spaces encoded as plus (+) signs. Spaces can alternatively be encoded as %20. 20 is (16*2)+(1*0)=32 in decimal, which is the ASCII code for space.


If You write


then Result will come like this