If we try to remove/delete a query string directly using below code, we will get an error - collection is read-only.
Request.QueryString.Remove("QSname")
In order to solve above error problem, we need to write below code before we remove them.
// reflect to readonly property
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("QSname");
The .NET Framework allows developers to use the same set of skills to rapidly buid great applications for the web, windows, services and more.
Remove Querystring item in ASP.NET
Subscribe to:
Post Comments (Atom)
Thanks for the post, very helpful!
ReplyDeleteJust one thing, you're missing a left parenthesis after "typeof".
I am glad it helped you.
ReplyDeleteThanks for the catch. I have corrected it.