Request對象派生自HttpRequest類,使 ASP.NET 能夠讀取客戶端在 Web 請求期間發送的 HTTP 值,從客戶端獲取信息,瀏覽器的種類,用戶輸入表單的數據,Cookies,客戶端認證等,對應的Response.Write 負責處理前者獲取的東西。
構造函數:public HttpRequest(string filename, string url, string queryString)
- filename: 與請求關聯的文件的名稱 ;url: 有關當前請求的 URL 的信息;q ueryString: 與請求一起發送的整個查詢字符串('?' 之后的所有內容)。
- 屬性:
名稱 | 用法 | 說明 |
AcceptTypes | String[] arr = Request.AcceptTypes; | 獲取客戶端支持的 MIME 接受類型的字符串數組。 |
AnonymousID | Request.AnonymousID | 獲取該用戶的匿名標識符(如果存在)。 |
ApplicationPath | Request.ApplicationPath | 獲取服務器上 ASP.NET 應用程序的虛擬應用程序根路徑。 |
AppRelativeCurrentExecutionFilePath | Request.AppRelativeCurrentExecutionFilePath | 獲取應用程序根的虛擬路徑,並通過對應用程序根使用波形符 (~) 表示法(例如,以“~/page.aspx”的形式)使該路徑成為相對路徑。 |
Browser | Request.Browser | 獲取或設置有關正在請求的客戶端的瀏覽器功能的信息。 |
ClientCertificate | Request.ClientCertificate | 獲取當前請求的客戶端安全證書。 |
ContentEncoding | String EncodingType; EncodingType = Request.ContentEncoding.EncodingName; |
獲取或設置實體主體的字符集。 |
ContentLength | Request.ContentLength | 指定客戶端發送的內容長度(以字節計)。 |
ContentType | String str; str = Request.ContentType; |
獲取或設置傳入請求的 MIME 內容類型。 |
Cookies | HttpCookie MyCookie; MyCookieColl = Request.Cookies; |
獲取客戶端發送的 Cookie 的集合。 |
CurrentExecutionFilePath | sw.WriteLine(Server.HtmlEncode(Request.CurrentExecutionFilePath)); | 獲取當前請求的虛擬路徑。 |
CurrentExecutionFilePathExtension | Request。CurrentExecutionFilePathExtension | 獲取 CurrentExecutionFilePath 屬性中指定的文件名的擴展名。 |
FilePath | Request.FilePath | 獲取當前請求的虛擬路徑。 |
Files | HttpFileCollection Files = Request.Files; | 獲取采用多部分 MIME 格式的由客戶端上載的文件的集合。 |
Filter | Request.Filter = new QQQ1(Request.Filter); | 獲取或設置在讀取當前輸入流時要使用的篩選器。 |
Form | NameValueCollection coll = Request.Form; String[] arr1 = coll.AllKeys; |
獲取窗體變量集合。
|
Headers | NameValueCollection coll = Request.Headers; String[] arr1 = coll.AllKeys; |
獲取 HTTP 頭集合。 |
HttpChannelBinding |
獲取當前 HttpWorkerRequest 實例的 ChannelBinding 對象。
|
|
HttpMethod | sw.WriteLine(Server.HtmlEncode(Request.HttpMethod)); | 獲取客戶端使用的 HTTP 數據傳輸方法(如 GET、POST 或 HEAD)。 |
InputStream | System.IO.Stream str = Request.InputStream; | 獲取傳入的 HTTP 實體主體的內容。 |
IsAuthenticated | Request.IsAuthenticated | 獲取一個值(true or false),該值指示是否驗證了請求。 |
IsLocal | Request.IsLocal | 獲取一個值(true or false),該值指示是否來自本地計算機。 |
IsSecureConnection | Request.IsSecureConnection | 獲取一個值(true or false),指示 HTTP 連接是否使用安全套接字(即 HTTPS)。 |
Item | 從 QueryString、Form、Cookies 或 ServerVariables 集合獲取指定的對象。 | |
LogonUserIdentity | if (!Request.LogonUserIdentity.IsAuthenticated) Response.Redirect("LoginPage.aspx"); |
獲取當前用戶的 WindowsIdentity 類型。 |
Params | NameValueCollection pColl = Request.Params; | 獲取 QueryString、Form、Cookies 和 ServerVariables 項的組合集合。 |
Path | Request.Path | 獲取當前請求的虛擬路徑。 |
PathInfo | sw.WriteLine(Server.HtmlEncode(Request.PathInfo)); | 獲取具有 URL 擴展名的資源的附加路徑信息。 |
PhysicalApplicationPath | sw.WriteLine(Server.HtmlEncode(Request.PhysicalApplicationPath)); | 獲取當前正在執行的服務器應用程序的根目錄的物理文件系統路徑 |
PhysicalPath | sw.WriteLine(Server.HtmlEncode(Request.PhysicalPath)); | 獲取與請求的 URL 相對應的物理文件系統路徑。 |
QueryString | string fullname1 = Request.QueryString["fullname"]; string fullname2 = Request["fullname"]; |
獲取 HTTP 查詢字符串變量集合。 |
RawUrl | Request.RawUrl | 獲取當前請求的原始 URL。 |
ReadEntityBodyMode | 獲取指示請求實體是否被讀以及如何被讀的值。 | |
RequestContext | 獲取當前請求的 RequestContext 實例。 | |
RequestType | sw.WriteLine(Server.HtmlEncode(Request.RequestType)); | 獲取或設置客戶端使用的 HTTP 數據傳輸方法(GET 或 POST)。 |
ServerVariables | NameValueCollection coll = Request.ServerVariables; String[] arr1 = coll.AllKeys; |
獲取 Web 服務器變量的集合。 |
TimedOutToken | 獲取請求超時時去除的 CancellationToken 對象。 | |
TotalBytes | Request.TotalBytes | 獲取當前輸入流中的字節數 |
Unvalidated | 提供對 HTTP 請求值的訪問權限,不觸發請求驗證。 | |
Url | Uri MyUrl = Request.Url; | 獲取有關當前請求的 URL 的信息。 |
UrlReferrer | Uri MyUrl = Request.UrlReferrer; | 獲取有關客戶端上次請求的 URL 的信息,該請求鏈接到當前的 URL。 |
UserAgent | String userAgent = Request.UserAgent; | 獲取客戶端瀏覽器的原始用戶代理信息。 |
UserHostAddress | sw.WriteLine(Server.HtmlEncode(Request.UserHostAddress)); | 獲取遠程客戶端的 IP 主機地址。 |
UserHostName | sw.WriteLine(Server.HtmlEncode(Request.UserHostName)); | 獲取遠程客戶端的 DNS 名稱。 |
UserLanguages | String[] userLang = Request.UserLanguages; | 獲取客戶端語言首選項的排序字符串數組。 |
方法:
名稱 | 用法 | 說明 |
Abort | Abort() | 強制地終止基礎 TCP 連接,會導致任何顯著的 I/O 失敗。 |
BinaryRead | public byte[] BinaryRead(int count) | 執行對當前輸入流進行指定字節數的二進制讀取。 |
Equals (Object) | person1a.Equals(person1b)); | 確定指定的對象是否等於當前對象。 |
GetBufferedInputStream | public Stream GetBufferedInputStream() | 獲取一個 Stream 對象,該對象可用於讀取傳入的 HTTP 實體主體。 |
GetBufferlessInputStream() | public Stream GetBufferlessInputStream() | 獲取一個 Stream 對象,該對象可用於讀取傳入的 HTTP 實體主體。 |
GetBufferlessInputStream (Boolean) | public Stream GetBufferlessInputStream( bool disableMaxRequestLength ) |
獲取能被用於讀取正在到來的 HTTP 實體正文的 Stream 對象, 同時隨意地禁止設置在 MaxRequestLength 屬性中的請求長度限制。 |
GetHashCode | public virtual int GetHashCode() | 作為默認哈希函數。 (繼承自 Object。) |
GetType | Object.GetType() | 獲取當前實例的 Type。 (繼承自 Object。) |
InsertEntityBody | public void InsertEntityBody() | 向 IIS 提供 HTTP 請求實體正文的副本。 |
InsertEntityBody(byte[], int, int) | public void InsertEntityBody(byte[] buffer, int offset, int count) | 向 IIS 提供 HTTP 請求實體正文的副本以及有關請求實體對象的信息。 |
MapImageCoordinates | public int[] MapImageCoordinates(string imageFieldName) | 將傳入圖像字段窗體參數映射為適當的 x 坐標值和 y 坐標值。 |
MapPath(string) | public string MapPath(string virtualPath) | 將指定的虛擬路徑映射到物理路徑。 |
MapPath(String, String, Boolean) | public string MapPath(string virtualPath,string baseVirtualDir,bool allowCrossAppMapping) | 將指定的虛擬路徑映射到物理路徑。 |
MapRawImageCoordinates | public double[] MapRawImageCoordinates(string imageFieldName) | 將傳入圖像字段窗體參數映射為適當的 x 和 y 坐標值。 |
SaveAs | public void SaveAs(string filename,bool includeHeaders) | 將 HTTP 請求保存到磁盤。 |
ToString | Object obj = new Object(); Console.WriteLine(obj.ToString()); |
返回表示當前對象的字符串。 (繼承自 Object。) |
ValidateInput | public void ValidateInput() | 對通過 Cookies 、Form 和 QueryString 屬性訪問的集合進行驗證。 |