HttpRequest.QueryString 屬性

定義

取得 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

屬性值

NameValueCollection

用戶端送出的查詢字串變數。 索引鍵和值已做 URL 解碼。

範例

下列程式碼範例示範兩種方式,可取得名為 「fullname」 的查詢字串變數值。 在每個案例中,如果 URL 是 http://www.contoso.com/default.aspx?fullname=Fadi%20Fakhouri ,則傳回的值會是 「Fadi Fakhouri」,因為 %20 是 URL 解碼成空白字元。 如果 URL 沒有 fullname 查詢字串識別碼,則傳回的值會是 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")

適用於

另請參閱