Click here to Skip to main content
13,043,898 members (48,649 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

70.2K views
10 bookmarked
Posted 7 Apr 2011

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

You may also be interested in...

Pro

Comments and Discussions

 
Questionthanks Pin
Member 426894718-Oct-16 0:41
memberMember 426894718-Oct-16 0:41 
QuestionThank you Pin
Member 1235752428-Feb-16 9:28
memberMember 1235752428-Feb-16 9:28 
GeneralMy vote of 1 Pin
Member 1087396227-Jun-14 7:58
memberMember 1087396227-Jun-14 7:58 
GeneralMy vote of 1 Pin
Member 1087396227-Jun-14 7:56
memberMember 1087396227-Jun-14 7:56 
QuestionQuerstring Removal Pin
Minu H17-Mar-13 23:46
memberMinu H17-Mar-13 23:46 
GeneralMy vote of 5 Pin
Lechu8117-Dec-12 6:11
memberLechu8117-Dec-12 6:11 
QuestionMy vote of 5 Pin
Gökmen BULUT5-Jun-12 23:50
memberGökmen BULUT5-Jun-12 23:50 
GeneralMy vote of 5 Pin
narenderkumardhull29-Apr-12 20:35
membernarenderkumardhull29-Apr-12 20:35 
GeneralRe: > Even though the unanimous vote is that the collection shou... Pin
Ankur\m/12-Apr-11 18:29
memberAnkur\m/12-Apr-11 18:29 
GeneralRe: > OP was talking about a single request Ah, that's what's h... Pin
Jeff Bowman12-Apr-11 7:46
memberJeff Bowman12-Apr-11 7:46 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 7 Apr 2011
Article Copyright 2011 by Toniyo Jackson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid