Export (0) Print
Expand All

HttpRequest Class

Enables ASP.NET to read the HTTP values sent by a client during a Web request.

System::Object
  System.Web::HttpRequest

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

public ref class HttpRequest sealed

The HttpRequest type exposes the following members.

  NameDescription
Public methodHttpRequestInfrastructure. Initializes an HttpRequest object.
Top

  NameDescription
Public propertyAcceptTypesGets a string array of client-supported MIME accept types.
Public propertyAnonymousIDGets the anonymous identifier for the user, if present.
Public propertyApplicationPathGets the ASP.NET application's virtual application root path on the server.
Public propertyAppRelativeCurrentExecutionFilePathGets the virtual path of the application root and makes it relative by using the tilde (~) notation for the application root (as in "~/page.aspx").
Public propertyBrowserGets or sets information about the requesting client's browser capabilities.
Public propertyClientCertificateGets the current request's client security certificate.
Public propertyContentEncodingGets or sets the character set of the entity-body.
Public propertyContentLengthSpecifies the length, in bytes, of content sent by the client.
Public propertyContentTypeGets or sets the MIME content type of the incoming request.
Public propertyCookiesGets a collection of cookies sent by the client.
Public propertyCurrentExecutionFilePathGets the virtual path of the current request.
Public propertyCurrentExecutionFilePathExtensionGets the extension of the file name that is specified in the CurrentExecutionFilePath property.
Public propertyFilePathGets the virtual path of the current request.
Public propertyFilesGets the collection of files uploaded by the client, in multipart MIME format.
Public propertyFilterGets or sets the filter to use when reading the current input stream.
Public propertyFormGets a collection of form variables.
Public propertyHeadersGets a collection of HTTP headers.
Public propertyHttpChannelBindingGets the ChannelBinding object of the current HttpWorkerRequest instance.
Public propertyHttpMethodGets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.
Public propertyInputStreamGets the contents of the incoming HTTP entity body.
Public propertyIsAuthenticatedGets a value indicating whether the request has been authenticated.
Public propertyIsLocalGets a value indicating whether the request is from the local computer.
Public propertyIsSecureConnectionGets a value indicating whether the HTTP connection uses secure sockets (that is, HTTPS).
Public propertyItemGets the specified object from the QueryString, Form, Cookies, or ServerVariables collections.
Public propertyLogonUserIdentityGets the WindowsIdentity type for the current user.
Public propertyParamsGets a combined collection of QueryString, Form, Cookies, and ServerVariables items.
Public propertyPathGets the virtual path of the current request.
Public propertyPathInfoGets additional path information for a resource with a URL extension.
Public propertyPhysicalApplicationPathGets the physical file system path of the currently executing server application's root directory.
Public propertyPhysicalPathGets the physical file system path corresponding to the requested URL.
Public propertyQueryStringGets the collection of HTTP query string variables.
Public propertyRawUrlGets the raw URL of the current request.
Public propertyReadEntityBodyModeGets a value that indicates whether the request entity body has been read, and if so, how it was read.
Public propertyRequestContextGets the RequestContext instance of the current request.
Public propertyRequestTypeGets or sets the HTTP data transfer method (GET or POST) used by the client.
Public propertyServerVariablesGets a collection of Web server variables.
Public propertyTimedOutTokenGets a CancellationToken object that is tripped when a request times out.
Public propertyTotalBytesGets the number of bytes in the current input stream.
Public propertyUnvalidatedProvides access to HTTP request values without triggering request validation.
Public propertyUrlGets information about the URL of the current request.
Public propertyUrlReferrerGets information about the URL of the client's previous request that linked to the current URL.
Public propertyUserAgentGets the raw user agent string of the client browser.
Public propertyUserHostAddressGets the IP host address of the remote client.
Public propertyUserHostNameGets the DNS name of the remote client.
Public propertyUserLanguagesGets a sorted string array of client language preferences.
Top

  NameDescription
Public methodAbortForcibly terminates the underlying TCP connection, causing any outstanding I/O to fail. You might use this method in response to an attack by a malicious HTTP client.
Public methodBinaryReadPerforms a binary read of a specified number of bytes from the current input stream.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetBufferedInputStreamGets a Stream object that can be used to read the incoming HTTP entity body.
Public methodGetBufferlessInputStream()Gets a Stream object that can be used to read the incoming HTTP entity body.
Public methodGetBufferlessInputStream(Boolean)Gets a Stream object that can be used to read the incoming HTTP entity body, optionally disabling the request-length limit that is set in the MaxRequestLength property.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInsertEntityBody()Provides IIS with a copy of the HTTP request entity body.
Public methodInsertEntityBody(array<Byte>, Int32, Int32)Provides IIS with a copy of the HTTP request entity body and with information about the request entity object.
Public methodMapImageCoordinatesMaps an incoming image-field form parameter to appropriate x-coordinate and y-coordinate values.
Public methodMapPath(String)Maps the specified virtual path to a physical path.
Public methodMapPath(String, String, Boolean)Maps the specified virtual path to a physical path.
Public methodMapRawImageCoordinatesMaps an incoming image field form parameter into appropriate x and y coordinate values.
Public methodSaveAsSaves an HTTP request to disk.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodValidateInputCauses validation to occur for the collections accessed through the Cookies, Form, and QueryString properties.
Top

The methods and properties of the HttpRequest class are exposed through the Request properties of the HttpApplication, HttpContext, Page, and UserControl classes.

To access data from the QueryString, Form, Cookies, or ServerVariables collections, you can write Request["key"], as shown in the example for the QueryString property.

NoteNote

Unicode support for HttpRequest class members requires IIS version 6.0 or later.

TopicLocation
How to: Pass Values Between ASP.NET Web PagesBuilding ASP .NET Web Applications
How to: Pass Values Between ASP.NET Web PagesBuilding ASP .NET Web Applications

The following examples access the HttpRequest instance for the current request by using the Request property of the Page class.

You can use simplified syntax for accessing data from the QueryString, Form, Cookies, or ServerVariables collections. You can write Request["key"].

The first example shows how to retrieve a query string value when loading a page.

No code example is currently available or this language may not be supported.

The next example shows how to check if the request is authenticated and retrieve the raw URL.

No code example is currently available or this language may not be supported.

A Visual Studio Web site project with source code is available to accompany this topic: Download.

This example uses the StreamWriter class to write the values of several HttpRequest class properties to a file. For properties that are of type string, the values are HTML encoded as they are written to the file. Properties that represent a collection are looped through, and each key/value pair that they contain is written to the file.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft