Collections Reference
The Request object in ASP.NET supports seven collections, four of which were supported in ASP (Cookies, Forms, QueryString, and ServerVariables), and three of which are new (Files, Headers, and Params).
The collections of the
Request
class support
the following common set of properties:
- AllKeys
Returns a string array of all keys in the collection.
- Count
Returns an integer count of name/value pairs in the collection.
-
Item(
Index|Key) Returns an instance of the collection class based on the index or passed-in key. This is the default property, which is why, for example, calling:
Response.Cookies (
KeyVal)returns the HttpCookie instance corresponding to
KeyVal.- Keys
Returns a collection of the keys for the collection.
In addition, each collection class exposes the following methods:
-
CopyTo(
Array,Index) Copies the contents of the collection object to the provided
Arrayargument, starting at the providedIndexargument. Note that the array must be dimensioned to a sufficient size to contain the collection before calling CopyTo.-
GetKey(
Index) Returns a string containing the key corresponding to the provided
Indexargument.
With the exception of the Cookies collection, the code used to access
keys and values in the collections the Request class exposes is nearly identical in every case. This similarity makes it simple to create your own reusable classes or methods for manipulating the values from these collections, regardless of which collection you are working ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access