Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Removing (Deleting) Querystring in ASP.NET

, 7 Apr 2011
Rate this:
Please Sign up or sign in to vote.
Removing (Deleting) Querystring in ASP.NET

We cannot delete a query string directly like below:

Request.QueryString.Remove("foo")

If you do this, you will get an error - collection is read-only. So, we need to write the below code before deleting the query string.

In C#:

PropertyInfo isreadonly = 
  typeof(System.Collections.Specialized.NameValueCollection).GetProperty(
  "IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);
// remove
this.Request.QueryString.Remove("foo");

In VB.NET:

Dim isreadonly As PropertyInfo = _
  GetType(System.Collections.Specialized.NameValueCollection).GetProperty(_
  "IsReadOnly", BindingFlags.Instance Or BindingFlags.NonPublic)
 
' make collection editable
isreadonly.SetValue(Me.Request.QueryString, False, Nothing)
 
' remove
Me.Request.QueryString.Remove("foo")
I hope that this will help you guys.

License

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

Share

About the Author

Toniyo Jackson
Software Developer
India India
No Biography provided

Comments and Discussions

 
GeneralRe: Thanks for waiting. Let me tell this once again - Changing ... PinmemberAnkur\m/11-Apr-11 21:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 7 Apr 2011
Article Copyright 2011 by Toniyo Jackson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid