Why has Request.QueryString["key"] stopped working?
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 开发者_Go百科like a very trivial problem but I can't figure out what's going on?!
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
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.
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 ;-)
your query string should be in /default.aspx?key =value then you will be able to access using ["key"] param
you can use
Request.QueryString.Count();
and get the count of querystring modifiy code accordingly
精彩评论