tags:

views:

519

answers:

4

I would like to parse the values from aspx pages, both what is passed before the ? and after it? So, what is the C# function that allows me to parse that out?

I would like to do something like:

var pageType = parameter.trimBefore?();

var pageString = parameter.trimAfter?();

Thanks for any advice.

+1  A: 

Try the Split method in string. You provide the delimiter, ?, in this case, and the method will divide the string into the string that comes before the character and after the character.

String[] urlComponents = myUrl.Split('?')
MedicineMan
+7  A: 

Request.QueryString and Request.Uri should get you those values without string manipulation.

Neil Barnwell
A: 

Use the HttpContext.Current.Request object? You can get the path information and the QueryString information off of it.

Brandon
A: 

Request.Url will give you a Uri object - sadly this won't give you the power you'd like over the querystring.

Something like Request.Url.Segments will give you a collection of all the parts before the ?

Then using Request.QueryString will give you a name-value collection of the querystring values - remember that some querystring elements can contain multiple comma-seperated values, which is why the example in the docs has an inner loop.

Zhaph - Ben Duguid