Request.QueryString as a String

sybe
sybe used Ask the Experts™
on
In Asp.Net Request.QueryString is a collection with no default value.
Is there a simple way of getting the complete querystring as a string. Or do I have to parse my way through the complete Request.RawURL.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Robb HillSenior .Net Full Stack Developer

Commented:
Yes..you can save the querystring as a session veriable or as an arraylist afterrequesting it to your page.


Simply itterate throug each element of the querystring....concataning each element to a string value....

Once the loop is finished you should have one lone string.

Hope this helps...

Author

Commented:
I do not want a collection. Querystring isn't always a collection.

myurl.aspx?1562892bhjkjhbnm

the querystring is not a collection of key/values. But it is a querystring. You can not iterate through that.
Robb HillSenior .Net Full Stack Developer

Commented:
well if you just want the querystring as a string...just simply save it as a string....
You would due this by taking each param passed in the string...and saving them ..
then creating recombining the values as a string.


Is this what you mean?   Or do you want the entire url that is passed
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
As I said, sometimes the querystring has no params, but is just a string. Concatenating key/values for a querystring without "=" will result is a querystring with "=" in your solution.

Anyway, I have created a function to parse it from Request.Rawurl.


Public Function GetQueryString() As String
    GetQueryString = ""
    Dim sUrl As String = System.Web.HttpContext.Current.Request.RawUrl
    Dim iQ As Integer = Instr(sUrl, "?")
    If iQ > 0 Then GetQueryString = Right(sUrl, Len(sUrl) - iQ)
End Function

Open in new window

Robb HillSenior .Net Full Stack Developer

Commented:
Here are some examples...it really is dependent of whats being passed and the format you are passing it..in terms of me coding this for you..but the concept is the same..


check this out.

http://www.asp-dev.com/main.asp?page=51

Author

Commented:
But to add to this: I was looking for a single asp.net built-in variable. It is not that I am unable to code a querystring together from the pieces that asp.net gives me, but I was wondering if asp.net has a single built-in solution. I could not find one, so I asked.

Apparently there is none.

Author

Commented:

this works:
Response.Write(Request.QueryString)


but this does not:
Dim sTest As String = Request.QueryString
Robb HillSenior .Net Full Stack Developer

Commented:
dim sTest as String = <%=Request.QueryString %>

Author

Commented:
That just gives a syntax error.
Robb HillSenior .Net Full Stack Developer

Commented:
check this while im looking at something else....still not what your looking for 100%...

I guess my question is...why would you want a function that does this?

Every scenario I have dealt with you always have to parse the collection...as that is kind of the point...

does your scenario need know parse...

if not maybe we can just cast the collection
Commented:
too easy.
Just use: Request.QueryString.ToString()

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial