Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to get value of QueryString inside QueryString

Reply
Thread Tools

How to get value of QueryString inside QueryString

 
 
Mehdi
Guest
Posts: n/a
 
      04-06-2006
Hi,

I get the following URL on page load:

http://www.server1.com?RedirectUrl=h...er2.com?id=777

So QueryString["RedirectUrl"] will return (after cleaning up via URL
Encode/decode) :
"http://www.server2.com?id=777"

However I am interested to get the value of "777" without using string
functions.

Any suggestions?



Kind Regards


Mehdi


 
Reply With Quote
 
 
 
 
Charlie@CBFC
Guest
Posts: n/a
 
      04-06-2006
You left off "&" delimiter...

http://www.server1.com?RedirectUrl=h...er2.com&id=777

string url = Request.QueryString["RedirectUrl"]
string id = Request.QueryString["id"]

Charlie

"Mehdi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I get the following URL on page load:
>
> http://www.server1.com?RedirectUrl=h...er2.com?id=777
>
> So QueryString["RedirectUrl"] will return (after cleaning up via URL
> Encode/decode) :
> "http://www.server2.com?id=777"
>
> However I am interested to get the value of "777" without using string
> functions.
>
> Any suggestions?
>
>
>
> Kind Regards
>
>
> Mehdi
>



 
Reply With Quote
 
 
 
 
Ray Booysen
Guest
Posts: n/a
 
      04-06-2006
Mehdi wrote:
> Hi,
>
> I get the following URL on page load:
>
> http://www.server1.com?RedirectUrl=h...er2.com?id=777
>
> So QueryString["RedirectUrl"] will return (after cleaning up via URL
> Encode/decode) :
> "http://www.server2.com?id=777"
>
> However I am interested to get the value of "777" without using string
> functions.
>
> Any suggestions?
>
>
>
> Kind Regards
>
>
> Mehdi
>
>


Use substring to retrieve all the chars after the ?. You can find the
starting position of ? using the String static methods too.
 
Reply With Quote
 
Mehdi
Guest
Posts: n/a
 
      04-06-2006
> You left off "&" delimiter...

& has not be left off as the value of the "RedirectUrl" is a FULL url
itself, and since there is only one querystring value in this url "?" is
required instead of "&". In other words id=777 is not the QueryString of
www.Server1.com

Thanks for the suggestion anyway.

Mehdi



"Charlie@CBFC" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> You left off "&" delimiter...
>
> http://www.server1.com?RedirectUrl=h...er2.com&id=777
>
> string url = Request.QueryString["RedirectUrl"]
> string id = Request.QueryString["id"]
>
> Charlie
>
> "Mehdi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> I get the following URL on page load:
>>
>> http://www.server1.com?RedirectUrl=h...er2.com?id=777
>>
>> So QueryString["RedirectUrl"] will return (after cleaning up via URL
>> Encode/decode) :
>> "http://www.server2.com?id=777"
>>
>> However I am interested to get the value of "777" without using string
>> functions.
>>
>> Any suggestions?
>>
>>
>>
>> Kind Regards
>>
>>
>> Mehdi
>>

>
>



 
Reply With Quote
 
Chris Fulstow
Guest
Posts: n/a
 
      04-06-2006
Hi,

Firstly, you might want to URL-encode the value of your RedirectUrl
parameter, some characters aren't allowed in the querystring, including
question marks. For more info about URL encoding and the
HttpUtility.HtmlEncode(String) function, see MSDN:
http://msdn2.microsoft.com/en-us/lib...6h(VS.80).aspx

Once you've got the encoded value of RedirectUrl from the QueryString
collection, you might need to HtmlDecode() it to get back the original
values:
http://msdn2.microsoft.com/en-us/lib...de(VS.80).aspx

Next, you need to get the querystring from you URL value. The easiest
way would be to use string functions to get everything to the right of
the "?", but you wanted to avoid this. Therefore, another approach
would be to create a Uri object from your URL string:
http://msdn2.microsoft.com/en-US/lib...ri(VS.80).aspx

Uri myUrl = new Uri("http://www.server2.com?id=777");

You can now get the querystring part of the URL using the Uri.Query
property:

string myQuery = myUrl.Query;

Finally, how do you get the value of the id parameter without using
string functions? You can use the HttpUtility.ParseQueryString()
method to parse your querystring into a NameValueCollection object:
http://msdn2.microsoft.com/en-US/library/ms150046.aspx

NameValueCollection queryCol = HttpUtility.ParseQueryString(myQuery);
idValue = queryCol["id"];

Note that ParseQueryString() is only supported in .NET 2.0+.

Hope this helps,
Chris

 
Reply With Quote
 
Mehdi
Guest
Posts: n/a
 
      04-06-2006
Chris,

Thanks for the help. It seems that I will end up using string functions to
extract the id from MyUrl.Query. ParseQueryString() would have been the
perfect solution if I had .NET 2.


Regards

Mehdi


"Chris Fulstow" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
>
> Firstly, you might want to URL-encode the value of your RedirectUrl
> parameter, some characters aren't allowed in the querystring, including
> question marks. For more info about URL encoding and the
> HttpUtility.HtmlEncode(String) function, see MSDN:
> http://msdn2.microsoft.com/en-us/lib...6h(VS.80).aspx
>
> Once you've got the encoded value of RedirectUrl from the QueryString
> collection, you might need to HtmlDecode() it to get back the original
> values:
> http://msdn2.microsoft.com/en-us/lib...de(VS.80).aspx
>
> Next, you need to get the querystring from you URL value. The easiest
> way would be to use string functions to get everything to the right of
> the "?", but you wanted to avoid this. Therefore, another approach
> would be to create a Uri object from your URL string:
> http://msdn2.microsoft.com/en-US/lib...ri(VS.80).aspx
>
> Uri myUrl = new Uri("http://www.server2.com?id=777");
>
> You can now get the querystring part of the URL using the Uri.Query
> property:
>
> string myQuery = myUrl.Query;
>
> Finally, how do you get the value of the id parameter without using
> string functions? You can use the HttpUtility.ParseQueryString()
> method to parse your querystring into a NameValueCollection object:
> http://msdn2.microsoft.com/en-US/library/ms150046.aspx
>
> NameValueCollection queryCol = HttpUtility.ParseQueryString(myQuery);
> idValue = queryCol["id"];
>
> Note that ParseQueryString() is only supported in .NET 2.0+.
>
> Hope this helps,
> Chris
>



 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      04-06-2006

Maybe you can figure out what Microsoft is doing by going here:
http://dotnet.di.unipi.it/Content/ss...cs-source.html



"Mehdi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I get the following URL on page load:
>
> http://www.server1.com?RedirectUrl=h...er2.com?id=777
>
> So QueryString["RedirectUrl"] will return (after cleaning up via URL
> Encode/decode) :
> "http://www.server2.com?id=777"
>
> However I am interested to get the value of "777" without using string
> functions.
>
> Any suggestions?
>
>
>
> Kind Regards
>
>
> Mehdi
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get value from asp:textbox inside Repeater datakix@gmail.com ASP .Net 2 08-08-2011 12:01 PM
Passing QueryString URL as a paremeter in QueryString Adeel Ahmad ASP General 1 03-07-2006 02:05 PM
how do I get the value for the value in the radio buttons inside t Eskimo ASP .Net Web Controls 0 02-07-2005 05:07 PM
How to enforce "&"inside my queryString? Mehdi ASP .Net 2 01-29-2005 11:54 AM
get the value of the position of JPanel inside the JFrame Frédéric Colombero Java 0 11-05-2003 07:25 AM



Advertisments