How can I remove item from querystring in asp.net using c#?
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.
Finally,
hmemcpy answer was totally for me and thanks to other friends who answered.
I grab the HttpValueCollection using Reflector and wrote the following code
var hebe = new HttpValueCollection(); hebe.Add(HttpUtility.ParseQueryString(Request.Url.Query)); if (!string.IsNullOrEmpty(hebe["Language"])) hebe.Remove("Language"); Response.Redirect(Request.Url.AbsolutePath + "?" + hebe );