HttpRequest.QueryString 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 HTTP 查詢字串變數的集合。
public:
property System::Collections::Specialized::NameValueCollection ^ QueryString { System::Collections::Specialized::NameValueCollection ^ get(); };
public System.Collections.Specialized.NameValueCollection QueryString { get; }
member this.QueryString : System.Collections.Specialized.NameValueCollection
Public ReadOnly Property QueryString As NameValueCollection
屬性值
客戶端傳送的查詢字串變數。 鍵與值則以 URL 解碼。
範例
以下程式碼範例展示了兩種方法來取得名為「fullname」的查詢字串變數的值。 在每種情況下,如果 URL 是 http://www.contoso.com/default.aspx?fullname=Fadi%20Fakhouri,則回傳的值是「Fadi Fakhouri」,因為 是 %20 URL 解碼成空格字元。 如果 URL 沒有查詢 fullname 字串 ID,回傳的值會是 null。
第一行程式碼只在查詢字串中尋找鍵「fullname」;第二行則在所有 HTTP 請求集合中尋找「fullname」鍵。 關於第二行的更多資訊,請參見 Item[]。
string fullname1 = Request.QueryString["fullname"];
string fullname2 = Request["fullname"];
Dim fullname1 As String = Request.QueryString("fullname")
Dim fullname2 As String = Request("fullname")