Microsoft KB Archive/254742

= HOW TO: Use a Generic Collection to Parse HTTP Form Data with ASP =

Article ID: 254742

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Active Server Pages 4.0
 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0
 * Microsoft Internet Information Services 5.1

-



This article was previously published under Q254742



We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 6.0 running on Microsoft Windows Server 2003. IIS 6.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:

http://www.microsoft.com/technet/security/prodtech/IIS.mspx



IN THIS TASK
SUMMARY
 * Create the Sample Pages

REFERENCES



SUMMARY
This step-by-step article describes how to parse form data easily when you use Microsoft Active Server Pages (ASP) by using a generic collection instead of by explicitly defining the ASP collection for GET or POST requests.

When you use ASP to process data that is entered on a Web page through a form, two different collections are used depending on which HTTP method is specified in the form declaration:
 * GET uses the Request.QueryString collection.
 * POST uses the Request.Form collection.

This article describes how to process form data regardless of which HTTP method is used on the form.

NOTE: You may receive an error message if you copy the examples directly from this article to Microsoft FrontPage. The angle brackets may appear as escaped HTML code. To work around this behavior, paste the script in a blank Notepad document, and then copy it from Notepad before you paste it in FrontPage.

back to the top

Create the Sample Pages
The following steps describe how to create a sample HTML page with two Web forms (one that uses the GET method and one that uses the POST method), and how to create a sample ASP page that processes the form by using either method.   Save the following HTML code as Getdata.htm in the root folder of an IIS Web site: POST   GET     Save the following ASP code as Showdata.asp in the root folder of an IIS Web site: <% @language="vbscript" %> <%  ' Declare a variable for the generic collection. Dim objRequest ' Determine the HTTP method used. If UCase(Request.ServerVariables("HTTP_METHOD")) = "GET" Then ' Use the QUERYSTRING collection with GET requests Set objRequest = Request.QueryString Else ' Use the FORM collection with POST requests. Set objRequest = Request.Form  End If   ' Escape and output the form data. Response.Write Server.HTMLEncode(objRequest("txtData")) %>                   

When you open Getdata.htm by using HTTP (that is, by using an address such as http://localhost/getdata.htm), you may use either form to view the form results.

back to the top

