2025-04-27 07:49:33 -04:00

156 lines
6.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<TITLE>QueryString</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
TempString = navigator.appVersion
if (navigator.appName == "Microsoft Internet Explorer"){
// Check to see if browser is Microsoft
if (TempString.indexOf ("4.") >= 0){
// Check to see if it is IE 4
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else {
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
}
}
else if (navigator.appName == "Netscape") {
// Check to see if browser is Netscape
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad()
Dim frmContents
On Error Resume Next
If Not Parent Is Nothing Then
Set frmContents = Parent.Contents
If Not frmContents Is Nothing Then
frmContents.Window.TOCSynch_Click
End If
End If
End Sub
//--></SCRIPT><META NAME="DESCRIPTION" CONTENT="Internet Information Services reference information">
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="MS-IT-LOC" Content="Internet Information Services">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H4><A NAME="_querystring"></A><SUP></SUP>QueryString</H4>
<P>The <B>QueryString </B>collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?). Several different processes can generate a query string. For example, the anchor tag </P>
<P>&lt;A HREF= "example?string=this is a sample"&gt;string sample&lt;/A&gt;</P>
<P>generates a variable named <I>string</I> with the value "this is a sample." Query strings are also generated by sending a form, or by a user typing a query into the address box of the browser.</P>
<H6>Syntax</H6>
<P><B>Request.QueryString(</B><I>variable</I><B>)</B>[<B>(</B><I>index</I><B>)</B>|<B>.Count</B>] </P>
<P>&nbsp;</P>
<H6>Parameters</H6>
<DL>
<DT><I>variable</I></DT>
<DD>Specifies the name of the variable in the HTTP query string to retrieve.<BR>
</DD>
<DT><I>index</I></DT>
<DD>An optional parameter that enables you to retrieve one of multiple values for <I>variable</I>. It can be any integer value in the range 1 to <B>Request.QueryString(</B><I>variable</I><B>).Count</B>.</DD>
</DL>
<H6>Remarks</H6>
<P>The <B>QueryString</B> collection is a parsed version of the QUERY_STRING variable in the <B>ServerVariables</B> collection. It enables you to retrieve the QUERY_STRING variable by name. The value of <B>Request.QueryString(</B><I>parameter</I><B>)</B> is an array of all of the values of <I>parameter</I> that occur in QUERY_STRING. You can determine the number of values of a parameter by calling <B>Request.QueryString(</B><I>parameter</I><B>).Count</B>. If a variable does not have multiple data sets associated with it, the count is 1. If the variable is not found, the count is 0.</P>
<P>To reference a <B>QueryString </B>variable in one of multiple data sets, you specify a value for <I>index</I>. The <I>index </I>parameter can be any value between 1 and <B>Request.QueryString(</B><I>variable</I><B>).Count</B>. If you reference one of multiple <B>QueryString</B> variables without specifying a value for <I>index</I>, the data is returned as a comma-delimited string.</P>
<P>When you use parameters with <B>Request.QueryString</B>, the server parses the parameters sent to the request and returns the specified data. If your application requires unparsed <B>QueryString</B> data, you can retrieve it by calling <B>Request.QueryString</B> without any parameters.</P>
<P>You can use an iterator to loop through all the data values in a query string. For example, if the following request is sent</P>
<PRE><CODE>http://localhost/script/directory/NAMES.ASP?Q=Fred&amp;Q=Sally
</CODE></PRE>
<P>and Names.asp contained the following script,</P>
<PRE><CODE>---NAMES.ASP---
&lt;%
For Each item In Request.QueryString("Q")
Response.Write Request.QueryString("Q")(item) &amp; "&lt;BR&gt;"
Next
%&gt;
</CODE></PRE>
<P>Names.asp would display the following:</P>
<PRE><CODE>Fred
Sally
</CODE></PRE>
<P>The preceding script could also have been written using <B>Count</B>.</P>
<PRE><CODE>&lt;%
For i = 1 To Request.QueryString("Q").Count
Response.Write Request.QueryString("Q")(i) &amp; "&lt;BR&gt;"
Next
%&gt;
</CODE></PRE>
<H6>Example</H6>
<P>The client request</P>
<PRE><CODE>/scripts/directory-lookup.asp?name=fred&amp;age=22
</CODE></PRE>
<P>results in the following QUERY_STRING value: </P>
<PRE><CODE>name=fred&amp;age=22.
</CODE></PRE>
<P>The <B>QueryString</B> collection would then contain two members, <CODE>name</CODE> and <CODE>age.</CODE> You can then use the following script: </P>
<PRE><CODE>Welcome, &lt;%= Request.QueryString("name") %&gt;.
Your age is &lt;%= Request.QueryString("age") %&gt;.
</CODE></PRE>
<P>The output would be </P>
<PRE><CODE>Welcome, Fred. Your age is 22.
</CODE></PRE>
<P>If the following script is used:</P>
<PRE><CODE>The unparsed query string is: &lt;%=Request.QueryString %&gt;
</CODE></PRE>
<P>The output would be</P>
<PRE><CODE>The unparsed query string is: name=fred&amp;age=22
</CODE></PRE>
<H6>Applies To</H6>
<P><A HREF="/iishelp/iis/htm/asp/vbob5ulw.htm"><B>Request</B> Object</A></P>
<H6>See Also</H6>
<P><A HREF="/iishelp/iis/htm/asp/vbob8q5h.htm"><B>ClientCertificate</B></A>, <A HREF="/iishelp/iis/htm/asp/vbob0z3o.htm"><B>Cookies</B></A>, <A HREF="/iishelp/iis/htm/asp/vbob4fl9.htm"><B>Form</B></A>, <A HREF="/iishelp/iis/htm/asp/vbob5vsj.htm"><B>ServerVariables</B></A></P>
<hr class="iis" size="1">
<p align="center"><em><a href="../../../common/colegal.htm">&copy; 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
</BODY>
</HTML>