Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 337
Poornima Avatar asked Jan 06 '11 09:01

Poornima


People also ask

How do you decode or encode a URL in JavaScript?

Decoding a URLdecodeURI() function − The decodeURI() function is used to decode the URI, i.e., converting the special characters back to the original URI language. decodeURIComponent() function − This function decodes the complete URL back to its original form.

Should I use encodeURI or encodeURIComponent?

If you have a complete URL, use encodeURI . But if you have a part of a URL, use encodeURIComponent .

What is encodeURI in JavaScript?

The encodeURI() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).


1 Answers

You can use escape ( http://www.w3schools.com/jsref/jsref_escape.asp ) or encodeURI ( http://www.w3schools.com/jsref/jsref_encodeuri.asp ) to encode on Javascript side.

On server side: For C# - Use System.Web.HttpUtility.UrlDecode to decode ( http://msdn.microsoft.com/en-us/library/adwtk1fy.aspx ) For Java - Use URLDecoder to decode ( http://download.oracle.com/javase/1.5.0/docs/api/java/net/URLDecoder.html ) For PHP - Use urldecode ( http://php.net/manual/en/function.urldecode.php )

like image 179
ndtreviv Avatar answered Oct 31 '22 09:10

ndtreviv