473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to get value of QueryString inside QueryString

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
Apr 6 '06 #1
6 16211
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" <no****@nojunkmail.nowhere> wrote in message
news:uK**************@TK2MSFTNGP02.phx.gbl...
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

Apr 6 '06 #2
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.
Apr 6 '06 #3
> 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" <fi********@verizon.net> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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" <no****@nojunkmail.nowhere> wrote in message
news:uK**************@TK2MSFTNGP02.phx.gbl...
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


Apr 6 '06 #4
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

Apr 6 '06 #5
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" <ch**********@hotmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr 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

Apr 6 '06 #6

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

"Mehdi" <no****@nojunkmail.nowhere> wrote in message
news:uK**************@TK2MSFTNGP02.phx.gbl...
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

Apr 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: aa | last post by:
I am passing a text parameter with querystring like ..asp?parameter How do I pass a parameter which itself contains the "=" character? Eg if parameter ="a=b" then the code will interpret is...
3
by: catweezle2010 | last post by:
Hello NG, I have three files (default.aspx, search.aspx and work.aspx). The way is: login on default (if session is newsession). The loginname I write into as sessionvariable (username). So I...
6
by: Joe | last post by:
Hello All: I have a webform (WebForm1.aspx) that retrieves a value from a database (_formSessionId) the first time that it is posted. After the user filles in the form, he/she clicks a Button...
1
by: ozzii | last post by:
Hi, Does anybody know how to parse the name value pairs in a querystring contained in a variable with asp? for those of you who might be confused, what i am trying to do is basically I have a...
2
by: Jeff | last post by:
ASP.NET 2.0 Below you see the signature of a method in my webproject. "int user" get its value from the "user" parameter in the querystring. The problem is that I'm wondering how I can make a...
2
by: sattu | last post by:
i have this command on page load event when page first time loaded value of querystring is 1 for Ex. but second time it becomes null i am doing paging in repeater cmd.CommandText = "select *...
1
by: Rajeesh123 | last post by:
I have a dom tree in asp with jscript(same kind of treeview in .net). when user clicks on it , I pass the id to a hidden field and update it with ajax. The main page has one if clause to get the...
4
by: Spoogledrummer | last post by:
Hi, I'm attempting to limit access to a page without creating a whole load of session values and there for re-writing the page. So I've come up with the following code on a test page<%@...
0
by: Aravind555 | last post by:
Hi How to get particular value from inside html code of a existing internet explorer page from excel macro (navigate the page by using app activate or any other with out using web query but by...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.