views:

104

answers:

5

I have a simple web form called default.aspx in the folder structure webroot/folder/

When I navigate to http://myapp/folder/?key=value the page returns fine and when I call

<%= Request.QueryString[0] %>

I get "http://myapp/folder/?key=value" rendered on the page. However if I call

<%= Request.QueryString["key"] %>

I get nothing, and when I call

<%= Request.QueryString[1] %>

I get "Index was out of range. Must be non-negative and less than the size of the collection."

This seems like a very trivial problem but I can't figure out what's going on?!

A: 

If you apply a breakpoint, and then hover over the QueryString in Visual Studio then you should be able to view all of the keys. Alternatively you can foreach over the collection and print out the key names to see if it's slightly different to what you're expecting.

Matthew Steeples
Hmm when I did a foreach over the collection I got one key called "page". This web form is within a Sitecore CMS project, but created in Visual Studio rather than through the Sitecore interface, I wonder if Sitecore is messing with the page before it renders
Nick Allen - Tungle139
+1  A: 

So it turns out that behind the scenes Sitecore turns the querystring into

?page=the-requested-page.aspx?key=value

But the url in the browser looks as requested. Obviously sticking a second ? in the actual url makes everything after the second ? disappear

Nick Allen - Tungle139
A: 

If you're doing something that isn't really supposed to be under Sitecore control (although I have never found it to make working with the QueryString collection impossible), try adding your /folder/ to the ignoreUrl setting. Sitecore will get out of your hair, then ;-)

Mark Cassidy
A: 

your query string should be in /default.aspx?key =value then you will be able to access using ["key"] param

Amit Ranjan
A: 

you can use

Request.QueryString.Count();

and get the count of querystring modifiy code accordingly

sree2010