I want remove "Language" querystring from my url. How can I do this? (using Asp.net 3.5 , c#)
Default.aspx?Agent=10&Language=2
I want to remove "Language=2", but language would be the first,middle or last. So I will have this
Default.aspx?Agent=20
A query string is a collection of characters input to a computer or web browser. A Query String is helpful when we want to transfer a value from one page to another.
To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.
If it's the HttpRequest.QueryString then you can copy the collection into a writable collection and have your way with it.
NameValueCollection filtered = new NameValueCollection(request.QueryString); filtered.Remove("Language");
Here is a simple way. Reflector is not needed.
public static string GetQueryStringWithOutParameter(string parameter) { var nameValueCollection = System.Web.HttpUtility.ParseQueryString(HttpContext.Current.Request.QueryString.ToString()); nameValueCollection.Remove(parameter); string url = HttpContext.Current.Request.Path + "?" + nameValueCollection; return url; }
Here QueryString.ToString()
is required because Request.QueryString
collection is read only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With