
AcceptTypes | 321
HttpRequest
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
If the key “myKey” exists in any of the collections that the HttpRequest class
exposed, the previous code will return it.
Although accessing values as shown in the previous example may
seem easy, there are two very good reasons not to use this method.
First, accessing values without specifying the collection in which
the value should be found requires ASP.NET to search through
each collection until it finds the key (if it finds it). While ASP.NET
generally performs significantly faster than ASP, there is still no rea-
son to suffer the unnecessary overhead of this method of accessing
values.
Second, using the method shown previously makes your code more
difficult to understand, debug, and maintain. Someone attempting
to understand how your page operates would not be able to figure
out from this code whether the page was expected to be accessed
via a GET request or a POST request. Explicitly specifying the
desired collection clarifies your intent and makes it easier to track
down a problem if your code doesn’t work.
In this chapter, we’ll use the following code listing as the basis for most examples
in the chapter. Unless otherwise noted, each example will consist of only the
Page_Load event handler for that particular example. Any displayed output
messages ...