Wednesday, 27 February 2013

Code to Encode, Decode URL and Query Strings in c# and javascript


In C#

using System; // Namespace
System.Uri -- Class Name

Uri.EscapeUriString or HttpUtility.UrlPathEncode --> to Encode actual Url path.
HttpUtility.UrlEncode("Stack Overflow") --> "Stack+Overflow" to encode query string parameters.

System.Uri.UnescapeDataString --> to Decode actual Url path or a string.
HttpUtility.UrlEncode("Stack+Overflow") --> "Stack Overflow" to encode query string parameters.


In JavaScript 

encodeURIComponent --> to encode URI or QueryString data
example:
encodeURIComponent(uri);

decodeURIComponent --> to decode a string that was URI encoded with the encodeURIComponent
example:
decodeURIComponent(uri);

No comments:

Post a Comment