Removing Items From QueryString

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,

When I call
Request.QueryString.Clear();

ASP.NET throws me this exception:

Exception Details: System.NotSupportedException: Collection is read-only

If the collection is read-onle, then why there is a Clear() method?

If I can not call Clear() methid in certain phases of QueryString's life
time, then how can I remove items from QueryString during postbacks?

Thanks,
Alan
 
The collection is readonly which means you can't modify it. Not at all - not
directly or indirectly.

The querystring can't be controlled from within the code, because by the
time your code fired it is already passed to you. This makes perfect sense
if you think about it <g>...

I'm guessing you want to modify the URL of the page? The only way to do this
is to Redirect to another page or possibly using some client script to
modify the Location. ASP.Net always posts back to the same URL and you
cannot change that from the server side...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 
Hi Alan,

I think Rick has provided enough information to you. What I want to tell is
that the Clear() method is a member of NameValueCollection class, which is
for general use.(HttpRequest.QueryString property return a
NameValueCollection object). While QueryString can not be modified by you,
so the Clear method can not be used.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Alan,

Does our reply make sense to you? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thank you Jeffrey,

That Clear method confused me. It does make sense QueryString be readonly.

However, technically, It should be quite doable to change QueryString by
*during post backs *. What do you think?
 
I think you missed one point,

Technically, It should be quite doable to change QueryString *during post
backs *

Is it implemented in ASP.NET?
 
A PostBack is simply an HTTP Request using the POST method, rather than the
GET method. The Query String is still read-only. The only way to change the
Query String is to Response.Redirect, which tells the browser to Request the
new URL you send it, with the parameters it has in it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

A.M said:
Thank you Jeffrey,

That Clear method confused me. It does make sense QueryString be readonly.

However, technically, It should be quite doable to change QueryString by
*during post backs *. What do you think?




"Jeffrey Tan[MSFT]" said:
Hi Alan,

Does our reply make sense to you? Do you still have concern on this issue?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top