HttpContext.Request 属性


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

 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属性提供对类的属性和方法的编程访问 HttpRequestThe Request property provides programmatic access to the properties and methods of the HttpRequest class. 由于 ASP.NET 页包含对 System.Web 包含) 类 (命名空间的默认引用 HttpContext ,因此可以 HttpRequest 在不使用对的完全限定类引用的情况下引用 .aspx 页上的成员 HttpContextBecause 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. 但是,如果你想要 HttpRequest 从 ASP.NET 代码隐藏模块使用的成员,则必须 System.Web 在模块中包括对命名空间的引用,以及对当前活动的请求/响应上下文和 System.Web 你要使用的中的类的完全限定引用。However, 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.BrowserFor example, in a code-behind page you must specify the fully qualified name HttpContext.Current.Request.Browser.


如果在对象不可用时尝试使用此属性,ASP.NET 将引发异常 HttpRequestASP.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.