What’s the difference between HttpServerUtility.UrlPathEncode and HttpServerUtility.UrlEncode? And when should I choose one over the other?
What’s the difference between HttpServerUtility.UrlPathEncode and HttpServerUtility.UrlEncode ? And when should I choose one
Share
Update: as of 4.5, per MSDN reference, Microsoft recommends to only use UrlEncode. Also, the information previously listed in MSDN does not fully describe behavior of the two methods – see comments.
The difference is all in the space escaping – UrlEncode escapes them into + sign, UrlPathEncode escapes into %20. + and %20 are only equivalent if they are part of QueryString portion per W3C. So you can’t escape whole URL using + sign, only querystring portion. Bottom line is that UrlPathEncode is always better imho