Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=120200017

QueryString

Request Object

The main function of Request object is the retrieving of HTTP request variables from the client.

Request.QueryString Collection

Request.QueryString Collection retrieves the variable values of  query string which is sent in the HTTP request.

Syntax:

Request.QueryString(variable)[(index)|.Count]

 Or in an ASP file. Imply

<% Request.QueryString(variable)[(index)|.Count] %>

Parameters:

variable

The parameter "variable" is the name of the variable in the HTTP query string to be retrieved. The data type of "variable" is string and is enclosed by quotation marks (" ").

index

The optional parameter "index" is the number of the index of a variable with multiple values in the HTTP query string to be retrieved. The data type of "index" is an integer and the range is from 1 to  Request.QueryString(variable).Count

.Count

The parameter "Count" is the optional information of the parameter "variable" with delimeter ".". The parameter "Count" is a read-only attribute to return the total number of the available values of the parameter " variable".

Remarks:

The HTTP query string is the string following the question mark (?) in an HTTP request. For example:

../../../../../default.asp?qrystring=qrystringtvalue

Although query string are usually generated by a response page output, query string are only strings contained in an request headers. The values of query strings can also be generated by any user. Therefore header data or user input should be encoded or be validated before using.

 The QueryString Collection is the detailed version of the Query_String variable of the ServerVariables Collection. With the Request.QueryString Collection, the value of query string can be retrieved by name.

For variable with multiple values, the value of Request.QueryString(variable) will be in form of an array of all values of the variable in the Query_String. And the number of multiple values of the variable can be obtained by  Request.QueryString(variable).Count. For single value varible,  Request.QueryString(variable).Count equal to 1. If the variable does not exist,   Request.QueryString(variable).Count equal to 0.

And therefore the multiple values of a variable can be referenced by the parameter "index",  Request.QueryString(variable)(index). and the range of the index is from 1 to  Request.QueryString(variable).Count.

However, if the index is not specified for a multiple values variable, the Request.QueryString(variable) will return all values in the form of comma-delimited string.

Besides, if there is no specified variable for the Request.QueryString(), the Request.QueryString() will return the unparsed QueryString data.

Since the multiple values of a variable is in the form of an array, the values of the variable can be retrieved using a for index loop or a for each element loop. 

Examples:

  • HTTP Request

    HTTP Request:

    ../../../../../default.asp?A=9&B=1&B=2

  • With no variable specified in Request.QueryString

    ASP script command:

    <%= Request.QueryString %>

    HTTP response output (Buffered):

    A=9&B=1&B=2

    HTML web page ouput:

    A=9&B=1&B=2

  • With variable A specified in Request.QueryString

    ASP script command:

    <%= Request.QueryString("A") %>

    HTTP response output (Buffered):

    9

    HTML web page ouput:

    9

  • With variable B specified in Request.QueryString

    ASP script command:

    <%= Request.QueryString("B") %>

    HTTP response output (Buffered):

    1, 2

    HTML web page ouput:

    1, 2

  • With variable B specified in Request.QueryString().Count

    ASP script command:

    <%= Request.QueryString("B").Count %>

    HTTP response output (Buffered):

    2

    HTML web page ouput:

    2

  • Loop for all values in variable B specified in Request.QueryString() by count

    ASP script command:

    <%
    For i=1 to Request.QueryString("B").count
    Response.Write Request.QueryString("B")(i) & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    1<br />
    2<br />

    HTML web page ouput:

    1
    2

  • Loop for all values in variable B specified in Request.QueryString() by item

    ASP script command:

    <%
    For Each item in Request.QueryString("B")
    Response.Write item & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    1<br />
    2<br />

    HTML web page ouput:

    1
    2

Link:http://output.to/sideway/default.asp?qno=120200018

Form

Request Object

The main function of Request object is the retrieving of HTTP request variables from the client.

Request.Form Collection

Request.Form Collection retrieves the element values of a form which is sent in the body of HTTP request with a form using the POST method.

Syntax:

Request.Form(element)[(index)|.Count]

 Or in an ASP file. Imply

<% Request.Form(element)[(index)|.Count] %>

Parameters:

element

The parameter "element" is the name of the form element in the form collection to be retrieved. The data type of "element" is string and is enclosed by quotation marks (" ").

index

The optional parameter "index" is the number of the index of a form element with multiple values in the form collection to be retrieved. The data type of "index" is an integer and the range is from 1 to  Request.Form(element).Count

.Count

The parameter "Count" is the optional information of the parameter "element" with delimeter ".". The parameter "Count" is a read-only attribute to return the total number of the available values of the parameter " element".

Remarks:

The HTTP form collection is the string posted to the HTTP request body with a form using the POST method.

Although HTTP form collections are usually generated by a response page output, HTTP form collection are only strings contained in an request headers. The values of HTTP form collection can also be generated by any user. Therefore header data or user input should be encoded or be validated before using.

The Form Collection is indexed by the names of the parameter elements in the request body. With the Request.Form Collection, the value of form element can be retrieved by name.

For element with multiple values, the value of Request.Form(element) will be in form of an array of all values of the element in the Form Collection. And the number of multiple values of the element can be obtained by  Request.Form(element).Count. For single value varible,  Request.Form(element).Count equal to 1. If the variable does not exist,   Request.Form(element).Count equal to 0.

And therefore the multiple values of a variable can be referenced by the parameter "index",  Response.Form(element)(index). and the range of the index is from 1 to  Response.Form(element).Count.

However, if the index is not specified for a multiple values element, the Request.Form(element) will return all values in the form of comma-delimited string.

Besides, if there is no specified element for the Request.Form(), the Request.Form() will return the unparsed Form Collection data. But when post data more than 100KB, the Request.Form cannot be used. And should be rewritten by using the Request.Binary Read method.

Since the multiple values of a element is in the form of an array, the values of the element can be retrieved using a for index loop or a for each element loop.  And for the name of the form element, a for each element loop should be used.

Examples:

  • HTTP form submit

    ASP script command:

    <% ... Request.Form ... %>
    <form action="../../../../../form.asp" method="post">
    A:<input name="A" value="9" size="4" />  and
    B:<input name="B" value="1" size="4" /> plus <input name="B" value="2" size="4" />
    <input type="SUBMIT" />
    </form>

    HTML web page ouput (Layout):

    A: and B: plus

    HTTP Request:

    ../../../../../form.asp

    HTTP Request Body:

    A=9&B=1&B=2

    CMD commands: 

    telnet sideway.to 80 (CR)
    Post /form.asp HTTP/1.1 (CR)
    Host: sideway.to (CR)
    Connection: keep-alive (CR)
    Content-Type: application/x-www-form-urlencoded(CR)
    Content-Length: 11(CR)
     (CR)

    (... Response ...)
    HTTP/1.1 100 Continue
    Server: Microsoft-IIS/5.1
    Date: Tue, 31 Jan 2012 15:19:08 GMT
    X-Powered-By: ASP.NET 

    A=9&B=1&B=2

    (... Response ...)

  • With no variable specified in Request.Form

    ASP script command:

    <%= Request.Form %>

    HTTP response output (Buffered):

    A=9&B=1&B=2

    HTML web page ouput:

    A=9&B=1&B=2

  • With variable A specified in Request.Form

    ASP script command:

    <%= Request.Form("A") %>

    HTTP response output (Buffered):

    9

    HTML web page ouput:

    9

  • With variable B specified in Request.Form

    ASP script command:

    <%= Request.QueryString("B") %>

    HTTP response output (Buffered):

    1, 2

    HTML web page ouput:

    1, 2

  • With variable B specified in Request.Form().Count

    ASP script command:

    <%= Request.Form("B").Count %>

    HTTP response output (Buffered):

    2

    HTML web page ouput:

    2

  • Loop for all values in variable B specified in Request.Form() by count

    ASP script command:

    <%
    For i=1 to Request.Form("B").count
    Response.Write Request.Form("B")(i) & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    1<br />
    2<br />

    HTML web page ouput:

    1
    2

  • Loop for all values in variable B specified in Request.Form() by item

    ASP script command:

    <%
    For Each item in Request.Form("B")
    Response.Write (item) & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    1<br />
    2<br />

    HTML web page ouput:

    1
    2

  • Loop for all form elements in the form by item

    ASP script command:

    <%
    For Each item in Request.Form
    Response.Write (item) & "<br />"
    Next
    %>

    HTTP response output (Buffered):

    A<br />
    B<br />

    HTML web page ouput:

    A
    B

Link:http://output.to/sideway/default.asp?qno=120200014

AppendToLog

Response Object

Another function of Response object is the response of HTTP request log entries to the server log entry.

Response.AppendToLog Method

Response.AppendToLog Method appends "a string" to the end of the serer log entry for the HTTP request.

Syntax:

AppendToLog(
    string
)

 Or in an ASP file. Imply

<% Response.AppendToLog (string) %>

Parameters:

string

The parameter "string" is the text to be appended to the log file. The data type of "string" is string and is enclosed by quotation marks (" "). And commas (,) cannot be used in the parameter "string" because fields in the server log are comma-delimited.

Return Values:

void

The Response.AppendToLog Method has no return values.

Remarks:

The Response.AppendToLog Method can be used multiple times in one section of script and the specified string will be appended to teh existing entry.

No comma (,) can be used in the parameter "string" because fields comma-delimted in the server log.

However, before the specified string can be appended to the server log, the URI Query option of the Extended Properties property sheet for the site should be enabled in the Properties of the site in Web Site tab  in Properties of the enable logging group.

Examples:

  •  Response.AppendToLog

    ASP script command:

    <% Response.AppendToLog "Custom Log Message" %>

Previous Month  FEB  2012  Next Month
SMTWTFS
1234
567891011
12131415161718
19202122232425
26272829

Previous Month  JUN  2014  Next Month
SMTWTFS
1234567
891011121314
15161718192021
22232425262728
2930

Sideway BICK Blog

07/02


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013