Skip navigation.

The Shortest Event Handler SyntaxAll recent postsMicrosoft AJAX Library Cheat Sheets: Adjusted for RTM, DomEvent and DomElement Added

HttpRequest.Params - A Helpful Quad

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.

Comments

Comment permalink 1 joe |
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.

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):