ASP.NET - How to remove the query string after / before? from passing the ASPX parameter?

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

I would like to do something like:

var pageType = parameter.trimBefore?();

var pageString = parameter.trimAfter?();

      

Thanks for any advice.

0


a source to share


4 answers


Try Split method in line. In this case, you provide the separator ?, And this method will split the string into the line that precedes the character and after the character.



String[] urlComponents = myUrl.Split('?')

      

+1


a source


Request.QueryString

and Request.Uri

should get those values ​​without string manipulation.



+8


a source


Use HttpContext.Current.Request object? You can get path information and QueryString information.

0


a source


Request.Url will give you the Uri - unfortunately it won't give you the power you would like to receive on request.

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

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

0


a source







All Articles