9

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

3 Answers 3

12

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

Sign up to request clarification or add additional context in comments.

5 Comments

my url is like this window.open ( "../EBox/ShowLetter.aspx?DocumentId="+DocumentID+"&SectionType=1&RecID="+RecipientID,'PrintMail' , features ); I want to retrieve the querystring DocumentId, SectionType,RecID. how can I get the values if the 3 querystrings
I can decode the whole url like what u said but how to get the querystrings from that
encode in javascript and to decode the url in c# and then to get the querystring values
see my updated answer. If its helpful to you then mark it as correct. :)
Beware: escape does not correctly escape all UTF-8 characters. Better to use encodeURI or encodeURIComponent.
4

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 )

Comments

3
  • Javascript unescape(_stringEncoded) same as HttpUtility.UrlDecode(_string) in C#
  • Javascript escape(_setringDecoded) same as HttpUtility.UrlEncode(_string) in C#

Encode/Decode both

javascript Encode

escape('raj kumar') //raj%20kumar

C# Decode

HttpUtility.UrlDecode("raj%20kumar") //raj kumar

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.