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
Array
argument, starting at the providedIndex
argument. 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
Index
argument.
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 ...
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.