My personal preference here is to rewrite the query or work with the valuecollection name at the bottom, but there are times when the business logic does not do those that are very useful, and sometimes really reflect what you need. In these circumstances, you can simply turn off the readonly flag for a moment as follows:
// 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("foo"); // modify this.Request.QueryString.Set("bar", "123"); // make collection readonly again isreadonly.SetValue(this.Request.QueryString, true, null);
annakata 08 Oct '09 at 8:45 2009-10-08 08:45
source share