Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,
I need to read a query string from a URL.
eg. www.xyz.com/what-is-your-name

How can I read this type of query string from URL?
I know I can user www.xyz.com/handlepage.aspx?s=what-is-your-name, but I don't want to specify query string handler here.

Prathamesh
Posted

You can use UrlData objects to get the data from the Url, for example if the URL to the page where you would read the name is like http://www.example.com/page/MyNameHere

The code to get the MyNameHere would be like this,

C#
var name = UrlData[0]; // first item in the Url, 


You can specify many more these objects in the URL, to remove the QueryStrings from the URL. Read Mike's post[^] for these URL informations.

Second method of this can be, to split the URL at the '/' and after that, get the last string from array. That will have the page and the QueryString, replace all of the known data with an empty string. Remaining would contain the name variable.

Still asking, why you don't want to use it anyways?
 
Share this answer
 
v2
Comments
/\jmot 8-Dec-14 14:17pm    
+5,good Answer.
Full Description here..

http://www.dotnetperls.com/querystring[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900