Link to home
Start Free TrialLog in
Avatar of sybe
sybe

asked on

Request.QueryString as a String

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.
Avatar of Robb Hill
Robb Hill
Flag of United States of America image

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...
Avatar of sybe
sybe

ASKER

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.
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
Avatar of sybe

ASKER

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

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
Avatar of sybe

ASKER

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.
Avatar of sybe

ASKER


this works:
Response.Write(Request.QueryString)


but this does not:
Dim sTest As String = Request.QueryString
dim sTest as String = <%=Request.QueryString %>
Avatar of sybe

ASKER

That just gives a syntax error.
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
ASKER CERTIFIED SOLUTION
Avatar of ajolly
ajolly
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial