HttpContext.Request 属性

定义

为当前 HTTP 请求获取 HttpRequest 对象。Gets the HttpRequest object for the current HTTP request.

public:
 property System::Web::HttpRequest ^ Request { System::Web::HttpRequest ^ get(); };
public System.Web.HttpRequest Request { get; }
member this.Request : System.Web.HttpRequest
Public ReadOnly Property Request As HttpRequest

属性值

当前 HTTP 请求的 HttpRequestThe HttpRequest for the current HTTP request.

异常

Web 应用程序正在 IIS 7 的“集成”模式下运行。The Web application is running under IIS 7 in Integrated mode.

注解

Request 属性提供对 HttpRequest 类的属性和方法的编程访问。The Request property provides programmatic access to the properties and methods of the HttpRequest class. 由于 ASP.NET 页包含对 System.Web 命名空间(包含 HttpContext 类)的默认引用,因此你可以在不使用对 HttpContext的完全限定类引用的情况下引用 .aspx 页上 HttpRequest 的成员。Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpRequest on an .aspx page without using the fully qualified class reference to HttpContext. 例如,可以使用 Request.Browser 获取客户端浏览器的功能。For example, you can use Request.Browser to get the capabilities of the client browser. 但是,如果要从 ASP.NET 代码隐藏模块使用 HttpRequest 的成员,则必须在模块中包含对 System.Web 命名空间的引用,并且必须包含对当前活动的请求/响应上下文和中的类的完全限定引用 @no__t要使用的 2However, if you want to use the members of HttpRequest from an ASP.NET code-behind module, you must include a reference to the System.Web namespace in the module and a fully qualified reference to both the currently active request/response context and the class in System.Web that you want to use. 例如,在代码隐藏页面中,必须指定 HttpContext.Current.Request.Browser的完全限定名称。For example, in a code-behind page you must specify the fully qualified name HttpContext.Current.Request.Browser.

备注

如果 HttpRequest 对象不可用,则 ASP.NET 将引发异常。ASP.NET will throw an exception if you try to use this property when the HttpRequest object is not available. 例如,在 global.asax 文件的 Application_Start 方法中,或在从 Application_Start 方法调用的方法中,这种情况都是如此。For example, this would be true in the Application_Start method of the Global.asax file, or in a method that is called from the Application_Start method. 此时,尚未创建 HTTP 请求。At that time no HTTP request has been created yet.

适用于