HttpContext.Request HttpContext.Request HttpContext.Request HttpContext.Request Property

定義

取得目前 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.

備註

屬性可讓您以程式設計方式存取HttpRequest類別的屬性和方法。 RequestThe Request property provides programmatic access to the properties and methods of the HttpRequest class. 由於 ASP.NET 網頁System.Web包含命名空間的預設參考 (其中HttpContext包含類別), 因此您HttpRequest可以在 .aspx 頁面上參考的成員, HttpContext而不需使用的完整類別參考。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命名空間的參考, 以及目前使用中要求/回應內容和的完整參考。您想要使用的類別。System.WebHowever, 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.

注意

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 方法呼叫的方法中, 這會是 true。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.

適用於