By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

adding an item to a QueryString

P: n/a
PJ6
I thought this was going to be simple. I want to take an HttpRequest and add
an item to the QueryString.

First I tried to add it directly, but I got a "Collection is read-only."
error. So I decided to construct my own, new HttpRequest based on the
contents of the old one (from within a class that inherits from Page):

Dim q As New
System.Collections.Specialized.NameValueCollection (Me.Request.QueryString)
q.Add("TEST", test)
Dim r As New HttpRequest(Me.Request.FilePath, Me.Request.Url.ToString,
q.ToString)

Only this doesn't work, q.ToString returns
"System.Collections.Specialized.NameValueCollectio n". Do I really have to
serialize the QueryString myself? Is there really no built-in method to do
this?

I'm sure I misinterpreted what the constructor wants for FileName, but the
documentation offers no comment. Why is there no corresponding property?

Paul
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Try perhaps Response.Redirect if you want to direct the browser to a new
page and/or with a new querystring...
Else explain us what you want to do...

(you can't change the current request, it is what it is and you just handle
this).

--

"PJ6" <no****@nowhere.net> a écrit dans le message de
news:ui**************@TK2MSFTNGP09.phx.gbl...
I thought this was going to be simple. I want to take an HttpRequest and add an item to the QueryString.

First I tried to add it directly, but I got a "Collection is read-only."
error. So I decided to construct my own, new HttpRequest based on the
contents of the old one (from within a class that inherits from Page):

Dim q As New
System.Collections.Specialized.NameValueCollection (Me.Request.QueryString)
q.Add("TEST", test)
Dim r As New HttpRequest(Me.Request.FilePath, Me.Request.Url.ToString,
q.ToString)

Only this doesn't work, q.ToString returns
"System.Collections.Specialized.NameValueCollectio n". Do I really have to
serialize the QueryString myself? Is there really no built-in method to do
this?

I'm sure I misinterpreted what the constructor wants for FileName, but the
documentation offers no comment. Why is there no corresponding property?

Paul

Nov 19 '05 #2

P: n/a
PJ6
> Try perhaps Response.Redirect if you want to direct the browser to a new
page and/or with a new querystring...


And - to repeat my qestion - can one build this new query string using the
built-in object model, or does the logic for this have to be coded by hand?

Paul
Nov 19 '05 #3

P: n/a
PJ6 wrote:
I thought this was going to be simple. I want to take an HttpRequest
and add an item to the QueryString.

First I tried to add it directly, but I got a "Collection is
read-only." error. So I decided to construct my own, new HttpRequest
based on the contents of the old one (from within a class that
inherits from Page):

Dim q As New
System.Collections.Specialized.NameValueCollection (Me.Request.QueryStr
ing) q.Add("TEST", test) Dim r As New
HttpRequest(Me.Request.FilePath, Me.Request.Url.ToString, q.ToString)

Only this doesn't work, q.ToString returns
"System.Collections.Specialized.NameValueCollectio n". Do I really
have to serialize the QueryString myself? Is there really no built-in
method to do this?


It doesn't really make a lot of sense to change a property of a request
you've already received (except debugging and testing).

Any object you might want to associate with a particular request at
this point in time can be passed by SessionState or HttpContext.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4

P: n/a
On Thu, 10 Nov 2005 13:10:16 -0500, PJ6 wrote:
Try perhaps Response.Redirect if you want to direct the browser to a new
page and/or with a new querystring...


And - to repeat my qestion - can one build this new query string using the
built-in object model, or does the logic for this have to be coded by hand?

Paul

Not that I know of. However, why don't you render a client-side hidden
field? It will be included in the QueryString
Nov 19 '05 #5

P: n/a
> It doesn't really make a lot of sense to change a property of a request
you've already received (except debugging and testing).

Any object you might want to associate with a particular request at
this point in time can be passed by SessionState or HttpContext.


Actually, it makes perfect sense in certain circumstances. Let's say
you want to change the behavior of an entire site in some universal way
without having to re-code the entire thing. Let's say you want to be
able to send in one querystring parm to the site, say "Mode2", and have
the site use a different stylesheet if "Mode2" is in the Querystring.

Well, that's all fine and dandy, but what happens the second you click
a link on the site? That parm and its value will be lost and the site
will switch back to the other stylesheet. If there was a way to check
the referrer and add the querystring to the current request if it was
present in the referrer, the value could be propagated at a high level,
and no other code would need to be changed. It would be like a
persistent querystring item - once present, always present. I wanted
to do this to provide my users a way to surf their site using a totally
different stylesheet without having to re-code the entire site to
handle new functionality.

I can think of other uses for this as well, but alas I haven't found a
good way to do it.

Dec 3 '05 #6

P: n/a
Well, writing that description got me thinking on the problem again,
and I solved it the best way I can think of. For my specific scenario,
I just put a check at the very beginning of Application_BeginRequest to
look for the parm. If it's not found, I check the referrer. If it's
found there, I immediately do a redirect, adding the parm.

This works well as long as the referrer is intact. Unfortunately, I've
got a third party navigation control that's clearing it out.

Dec 4 '05 #7

P: n/a
Ferret wrote:
It doesn't really make a lot of sense to change a property of a
request you've already received (except debugging and testing).

Any object you might want to associate with a particular request at
this point in time can be passed by SessionState or HttpContext.


Actually, it makes perfect sense in certain circumstances. Let's say
you want to change the behavior of an entire site in some universal
way without having to re-code the entire thing. Let's say you want
to be able to send in one querystring parm to the site, say "Mode2",
and have the site use a different stylesheet if "Mode2" is in the
Querystring.

Well, that's all fine and dandy, but what happens the second you click
a link on the site? That parm and its value will be lost and the site
will switch back to the other stylesheet. If there was a way to check
the referrer and add the querystring to the current request if it was
present in the referrer, the value could be propagated at a high
level, and no other code would need to be changed. It would be like a
persistent querystring item - once present, always present. I wanted
to do this to provide my users a way to surf their site using a
totally different stylesheet without having to re-code the entire
site to handle new functionality.


All of that can be easily done using cookies or a some object in the
user's session. Heck, you could even do that with query strings. Of
course not for the current request, but all subsequent ones -- append
the key Mode2 to each and every URL you render in your pages... ouch ;-)

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Dec 6 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.