HttpRequest.QueryString HttpRequest.QueryString HttpRequest.QueryString HttpRequest.QueryString Property

定義

取得 HTTP 查詢字串變數的集合。Gets the collection of HTTP query string variables.

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

屬性值

用戶端送出的查詢字串變數。The query string variables sent by the client. 索引鍵和值已做 URL 解碼。Keys and values are URL-decoded.

範例

下列程式碼範例示範兩種方式可取得名為 「 fullname 」 的查詢字串變數的值。The following code example shows two ways to get the value of a query string variable named "fullname". 在每個案例中,如果 URL http://www.contoso.com/default.aspx?fullname=Fadi%20Fakhouri,則傳回的值是"Fadi Fakhouri",因為%20是 URL 解碼成的空格字元。In each case, if the URL is http://www.contoso.com/default.aspx?fullname=Fadi%20Fakhouri, then the value returned is "Fadi Fakhouri" because the %20 is URL-decoded into a space character. 如果 URL 不一定fullname查詢字串 ID,傳回的值會是nullIf the URL doesn't have a fullname query string ID, the returned value would be null.

第一行程式碼會尋找 「 fullname 」 只能在查詢字串中; 中的索引鍵第二行會尋找 「 fullname 」 中的所有 HTTP 要求集合的索引鍵。The first line of code looks for the key "fullname" only in the query string; the second line looks for the key "fullname" in all of the HTTP request collections. 如需有關第二行的詳細資訊,請參閱Item[String]For more information about the second line, see Item[String].

string fullname1 = Request.QueryString["fullname"];  
string fullname2 = Request["fullname"];  
Dim fullname1 As String = Request.QueryString("fullname")  
Dim fullname2 As String = Request("fullname")  

適用於

另請參閱