How to encode url in javascript and decode it in C#

Poornima picture Poornima · Jan 6, 2011 · Viewed 18.3k times · Source

I have a url with querystrings through which some data are passed. I want to retrieve the data in the server side. What is the solution for this problem

Answer

eHussain picture eHussain · Jan 6, 2011

You can use javascript's escape function to encode the URL.

Example : 
escape("It's me!") // result: It%27s%20me%21

URL Decoding in C# using Uri.UnescapeDataString() function.

Example : 
s = "%46%69%67%68%74%20%74%68%65%20%70%6F%77";
Uri.UnescapeDataString(s); 

EDIT -------------------------

To Parse Query parameters in C# use

NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);

Hope this will help.

Thanks!

Hussain