views:

25

answers:

2

I am trying to set up a page that has two behaviors. I'm seperating them by URL: One behavior is accessed via /some-controller/some-action, the other is via /some-controller/some-action?customize.

It doesn't look like the Request.QueryString object contains anything, though, when I visit the second URL...I mean, the keys collection has one element in it, but it's null, not 'customize'. Anyone have any ideas about this or how to enable this. I'd like to avoid manually parsing the query string at all costs :).

A: 

ASP.NET does not support determining the presence of query string parameters without values since Request.QueryString["customize"] and Request.QueryString["foo"] are both null. You'll either have to parse it yourself or specify a value e.g. ?customize=1

John Sheehan
Suddenly realizing I may be wrong and it might be possible to do `Request.QueryString.HasKey("customize")` but I remember going down this road in the past and not being able to find a solution
John Sheehan
After searching around, it looks like the QueryString dictionary values are only populated with parameters that have both a name AND a value so HasKey won't work.
John Sheehan
Indeed. What's particularly funny about it, though, is if you do supply a `?customize` query string, the QueryString dictionary will populate a single key, but it is null in the collection -- it doesn't have a related value, for whatever reason. Kind of strange behavior I think!
Brad Heller
+2  A: 

You can test the value of Request.Url.Query if ?customise is the only think you're looking for.

Robin Day
This is the best solution, I think. I just did `Request.Url.Query.StartsWith()`. When dealing with semantic URLs it would be REALLY great to have support for this out of the box!
Brad Heller