HttpRequest.Params - A Helpful Quad

Posted on January 14, 2007  |  

Posted in Development

1 comment

Another interesting find of the day: I’ve never noticed a handy property, HttpRequest.Params, which “flattens” four collections into one, namely QueryString, Form, ServerVariables, and Cookies.

The other day I was writing a RESTful web service, and I needed a way to accept parameters via both POST and GET. HttpRequest.Params gives me a uniform collection of everything submitted over the wire. This is really cool.

It’s odd that “HttpRequest.Params” doesn’t conform to the naming guidelines. But as Jack Sparrow’s acolytes would’ve said, They are merely guidelines, not The Pirate Code.

1 comment

joe
on January 15, 2007

While you are on the subject of shorter code, Request["key"] will do the same as Request.Params["key"].

I have actually fallen into the habit of coding up most of my forms using this and only using .Form or the others when needing them.

The thing I don't like about it though is the order of the places it looks for what to return. The collection in my mind should check the Form post first then the QueryString, not the other way around.


Leave a comment

  •