Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

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

BinaryRead / TotalBytes

Request Object

Another function of Request object is the retrieving of HTTP data of a POST request from the client.

Request.BinaryRead Method

Request.BinaryRead Method retrieves the data part of a POST request by the server from the client.

Syntax:

BinaryRead(
    count
)

 Or in an ASP file. Imply

<% Request.BinaryRead(count) %>

Parameters:

count

The paramete "count" is used to specify the number of bytes to be read from the client. The total number of bytes that actually be read is less than or equal to Request.TotalBytes. "count" contains the number of bytes successfully read from the client after method return.

Return Values:

Return Values by this method contains an array of unsigned bytes. The data type of the return values is VT_ARRAY | VT_UI1, which is a variant array of unsigned, one-byte characters.

Remarks:

Data retrieves by the method from the client is stored in a SafeArray that contains information about the number of dimensions and the bounds of its dimensions.

 The BinaryRead method is used to read the raw data sent by the client as part of a POST request. The raw data, which unlike the field variable format using the Request.Form collection, is a low-level format of data.

Examples:

  • HTTP form with POST method by BinaryRead

    ASP script command:

    <%
    If Request.QueryString("binread")="y" then
        bin_total = Request.TotalBytes
        bin_req= Request.BinaryRead(bin_total)
        for i = 1 to bin_total
            Response.Write MidB(bin_req,i,1)
        next
    end if
    %>
    <form action="../../../../../form.asp?binread=y" 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>

    HTTP Request (by Submit button):

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

    HTML web page ouput (Layout):

    A: and B: plus

    HTTP Request (by Submit button):

    ../../../../../form.asp?binread=y

    HTML web page ouput (Layout):

    A: and B: plus

    A=9&B=1&B=2

Request.TotalBytes Property

Request.TotalBytes Property is a read only property to specify the total number of bytes sent by the client in the body of the HTTP request

Syntax:

Request.TotalBytes()

 Or in an ASP file. Imply

<% Request.TotalBytes() %>

Parameters:

void

This property has no parameters. A variable should assign to the Request.TotalBytes for receiving the total number of bytes sent by the client.

Remarks:

A read only property.

Examples:

  • Assign Request.TotalBytes to bin_total

    ASP script command:mmand:

    <%
        bin_total = Request.TotalBytes
    %>

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

CreateObject

Server Object

The main function of Server object is the create an instance of object on the server.

Server.CreateObject Method

Server.CreateObject Method creates an instance of an object from a server component on the server.

Syntax:

CreateObject(
    progID
)

 Or in an ASP file. Imply

<% Server.CreateObject(progID) %>

Parameters:

progID

The paramete "progID" is used to specify the type of object to create on the server. The format for progID is [Vendor.]Component[.Version].

Return Values:

This method has no return values.

Remarks:

If the component has implementd the OnStartPage and OnEndPage methods, the OnStartPage method will be called when the component is called by the CreateObject method.

By default, objects created by the Server.CreateObject method have page scope. And therefore objects created during the processing of an ASP page will be destroyed automatically by the server after the completion of the page response. 

In order to create object with session or application scope, the object can be created by using the <OBJECT> tag in the Global.asa file and set the SCOPE attribute to SESSION or APPLICATION,. Or the oject can be stored in a session or an application variable. Similarly, the created object will be destroyed when the Session or Application object is destroyed.

A Session object will be destroyed when the session times out, or the Session.Abandon method is called. But an object can be destroyed by setting the variable of an object to Nothing or setting the variable to a new value.

But an object instance can not be created with the same name as a build-in object.

Examples:

  • Creation of an instance of object from a server component, "MSWC.AdRotator" in page scope.

    ASP script command:

    <%
    Set AdRot = Server.CreateObject("MSWC.AdRotator")
    %>

  • Creation of an instance of object from a server component, "MSWC.AdRotator" in session scope.

    ASP script command:

    <%
    Set Session("AdRot") = Server.CreateObject("MSWC.AdRotator")
    %>

  • Destroy the instance of object with page scope.

    ASP script command:

    <%
    Set AdRot = Nothing
    %>

  • Create an object instance with the same name as a built-in object is not allowed.

    ASP script command:

    <%
    ' Error
    Set Response = Server.CreateObject("Response")
    %>

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

Execute

Server Object

Another function of Server object is the execution of file on the server.

Server.Execute Method

Server.Execute Method execute an ASP file similar to a procedure call on the server.

Syntax:

Execute(
    Path
)

 Or in an ASP file. Imply

<% Server.Execute(Path) %>

Parameters:

Path

The paramete "Path" is used to specify the location of the ASP file to execute. The parameter Path may be either an absolute or a relative path. For an absolute Path, the path must map to an ASP script in the same application as the calling ASP file. Path can be a string variable name that is set at run-time. But the parameter Path must not contain a query string, or IIS returns an error.

Return Values:

This method has no return values.

Remarks:

The Server.Execute method calls an ASP file similar to a procedure call, and processes it as part of the calling ASP script.

The Server.Execute method allows the dividing of a complex application into indivuidual modules. These ASP files forms a library that can be called whenever necessary. The Server.Execute method provides the method to call an ASP file dynamically and can be considered as an alternative approach to server-side include directives.

The Server.Execute method returns the ASP 0173 error, "Invalid Path Character", if the parameter Path contains any of the following characters:

  • Asterisk (*)

  • Question mark (?)

  • Angle brackets (< or >)

  • Comma (,)

  • Colon or semi-colon (: or :)

  • Single-quote or double-quote (' or ")

  • Right square bracket (])

  • Double slashes (// or \\)

After IIS processes the ASP file specified in the input parameter to Server.Execute, the response is returned to the calling ASP script.

The following collections and properties are available to the executed ASP page:

  • Application variables, even if they are set in the calling page.

  • Session properties, even if they are set in the calling page

  • Server variables and properties, even if they are set in the calling page. This includes Form and QueryString data passed to the calling page.

  • Response collections and properties. The executed ASP file may modify HTTP headers. However, as with any ASP file, if the executed ASP file attemps to modify HTTP headers after it sends a response to the client, it generates an error.

If a file is included in the calling page by using #include, the executed ASP will not use it.

If either the calling or called ASP file conttains a transaction directive, the status of the transaction will apply to the ASP file that contains the directive.

Examples:

  • Implement Server.Execute method as a dynamical call of an ASP file  .

    ASP script command:

    <%
    langchoice = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
    Server.Execute(langchoice & "default.asp")
    %>

  • Server.Execute will not process the "#include" line in the called page.

    ASP script command:

    -----calling page-----
    <%
    Function Test
    End Function
    Server.Execute("called .asp")
    %>

    -----called page-----
    <%
    ' Function Not Available
    Call Test
    %>

  • Transaction status will apply to the ASP file that contains the transaction directive.

    ASP script command:

    -----calling page-----
    <@ Transaction=Required %>
    <%
    Server.Execute("called .asp")
    Sub OnTransactionAbort
    Sub OnTransactionCommit
    %>

    -----called page-----
    <@ Transaction=Required %>
    <%
    ' Function Not Available
    Sub OnTransactionAbort
    Sub OnTransactionCommit
    %>

    -----Transaction Abort while called page is being processed-----
    The OnTransactionAbort subroutine of called page will be called if present.
    After the completion of the called page and return to calling page.
    The OnTransactionAbort subroutine of calling page will be called if present.

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

09/02


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