Get a querystring key name

N

.NET Developer

Ok, this is probably simple but it's been driving me nuts.

If I have a URL like this: http://www.mysite.com/MyPage.aspx?MyKey

What code would I write to get that value "MyKey" out of the querystring?
Without the = and a value after it, is it considered a querystring value
still? I've tried Request.Params[0], Request.QueryString.Key[0], and nothing
is returning the value to me. I've driven down several levels into the
debugger and found the value (nested several object hierarchy levels deep)
but can't figure out how to get access to it.

Help?
 
N

.NET Developer

Nope...doesn't work (at least not in asp.net 1.1)

I found something that seems to work for now:

Request.Url.Query.Replace("?","");

Gets me what I need - just doesn't seem like the "right' way to get it.

Scott M. said:
Request.QueryString(0).Name


.NET Developer said:
Ok, this is probably simple but it's been driving me nuts.

If I have a URL like this: http://www.mysite.com/MyPage.aspx?MyKey

What code would I write to get that value "MyKey" out of the querystring?
Without the = and a value after it, is it considered a querystring value
still? I've tried Request.Params[0], Request.QueryString.Key[0], and
nothing is returning the value to me. I've driven down several levels
into the debugger and found the value (nested several object hierarchy
levels deep) but can't figure out how to get access to it.

Help?
 
K

Ken Cox [Microsoft MVP]

You can use GetKey for that. Here's some code. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

Try
' Make sure you pass everything such as
' ?mykey=4
Response.Write(Request.QueryString.GetKey(0))
Catch exc As Exception
Response.Write(exc.Message)
End Try
 
N

.NET Developer

Well, you see, that's part of the problem I have to solve - I can't
guarantee the key will have "=[value]" after it. Which causes GetKey(0) to
fail.

Don't you think ?mykey should make GetKey(0) contain "mykey" ? Seems logical
to me. I don't think keys should be dependent on associated values.

Ken Cox said:
You can use GetKey for that. Here's some code. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

Try
' Make sure you pass everything such as
' ?mykey=4
Response.Write(Request.QueryString.GetKey(0))
Catch exc As Exception
Response.Write(exc.Message)
End Try

.NET Developer said:
Ok, this is probably simple but it's been driving me nuts.

If I have a URL like this: http://www.mysite.com/MyPage.aspx?MyKey

What code would I write to get that value "MyKey" out of the querystring?
Without the = and a value after it, is it considered a querystring value
still? I've tried Request.Params[0], Request.QueryString.Key[0], and
nothing is returning the value to me. I've driven down several levels
into the debugger and found the value (nested several object hierarchy
levels deep) but can't figure out how to get access to it.

Help?
 
D

Dotnet Gruven

if (this.Request.QueryString.AllKeys.Length == 1)

{

string keyName = this.Request.QueryString[0];

}



HTH,

g
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top