devguru asp quickref

Upload: gary-li

Post on 09-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 DevGuru ASP Quickref

    1/85

    Quick Reference Library

    ASP Quick Reference

    Copyright 1999-2002 by Infinite Software Solutions, Inc. All rights reserved.

    Trademark Information.

  • 8/8/2019 DevGuru ASP Quickref

    2/85

    elcome to the DevGuru Built-in ASP Objects Quick Reference guide. This is a valuable 71

    ge reference source that explains and provides comprehensive, working examples of codeall of the collections, events, methods, and properties belonging to the seven Built-in Active

    rver Pages objects.

    e seven built-in objects are:Application

    ASPError

    ObjectContextRequest

    Response

    Server

    Session

    the good old days (a few years ago!), most Web sites were created with HTML and simplyplayed static pages. A few of the more adventurous programmers would use C or Perl to

    sign a dynamic Web site utilizing the CGI technology. However, these techniques wereagued with security concerns and did not scale well to large sites. So, in general, dynamices remained relatively few in number and were time consuming and expensive to create.

    e introduction of the scripting languages, which could be embedded inside HTML code,ened new doors for dynamic site development. Active Server Pages (ASP), which managedarrive just in time for the explosive growth of the World Wide Web, was a next logical stepWeb-based application development. Introduced in 1996 by Microsoft, Active Server Pages

    oved to be an exciting, new technology that extended standard HTML by adding built-inects, server-side scripts, access to databases, and ActiveX components. Another important

    velopment by Microsoft was to make the ASP scripting environment compliant with themponent Object Model (COM). COM created a standard communication mechanismtween components. This step allowed non-vendor components, such as those offered by

    vGuru, to share their properties, methods and events with other components in a process

    led OLE automation. Non-vendor components greatly extend the functionality of ASPplications.

    e true power of ASP is the ease and rapidity with which developers can create andplement dynamic Web sites. Indeed, for today's modern Web commerce, a dynamic,tabase-driven, server-side application that interacts with the client is the norm.

    P employs a scripting environment and VBScript is the default scripting language of choice.

    wever, you can use other languages (such as JScript and Perl) as long as they have a

    ripting engine that is compatible with the ActiveX scripting standard.

    rtunately, you are not limited to just using Active Server Pages with Microsoft's Internetormation Server (IIS) and this has enhanced the popularity of ASP. For example, Chili!Soft is

    proven industry leader in providing ASP engines for use with Web servers from FastTrack,

    tus, Netscape, O'Reilly, and many others. And Halcyon Software offers a brilliant Java-sed implementation of the Microsoft ASP framework, allowing developers to deploy ASPplications on any platform.

    eanwhile, ASP continues to evolve. With the arrival of the millennium came the arrival of ASPrsion 3.0. Version 3.0 was released along with Internet Information Server (IIS) version 5.0

    part of the highly anticipated Microsoft Windows 2000. By far, the most important newature of version 3.0 is the addition of a seventh, intrinsic object called ASPError which should

    eatly simplify error handling. Other new features include the addition of three new methods toe Server object, and two new methods to both the Application object and the Session object.

    http://technologies/vbscript/quickref/vbscript_intro.htmlhttp://technologies/vbscript/quickref/vbscript_intro.html
  • 8/8/2019 DevGuru ASP Quickref

    3/85

    tive Server Pages has ultimately proven to be of significant value to developers and fueled avolution in the development of Web-based applications.

    e future of ASP will continue to be very interesting. Later this year (summer?), ASP-plus,ich is now referred to as ASP.NET, will be formally released by Microsoft. It allows the use

    the Visual Basic, C#, and Visual C++ languages with ASP.

  • 8/8/2019 DevGuru ASP Quickref

    4/85

    ntentsApplication

    Session

    entCertificate

    okiesRequest

    Response

    m

    eryString

    rverVariables

    ticObjectsApplication

    Session

  • 8/8/2019 DevGuru ASP Quickref

    5/85

  • 8/8/2019 DevGuru ASP Quickref

    6/85

    andon

    dHeader

    pendToLog

    aryRead

    aryWrite

    ar

    ntents.RemoveApplication

    Session

    ntents.RemoveAllApplication

    Session

    CreateObject

    End

    Execute

    Flush

    GetLastError

    HTMLEncode

    MapPath

    Redirect

    SetAbort

    SetComplete

    Transfer

    URLEncode

    Write

  • 8/8/2019 DevGuru ASP Quickref

    7/85

    plication

    PError

    ectContext

    quest

    sponse

    rver

    ssion

  • 8/8/2019 DevGuru ASP Quickref

    8/85

    PCode

    PDescription

    fer

    cheControl

    egory

    arset

    dePage

    umn

    ntentType

    scription

    pires

    piresAbsolute

    File

    IsClientConnected

    LCID

    Line

    Number

    Pics

    ScriptTimeout

    SessionID

    Source

    Status

    Timeout

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 8/8/2019 DevGuru ASP Quickref

    9/85

    andon

    dHeader

    pendToLog

    plication

    PCode

    PDescription

    PError

    aryRead

    aryWrite

    fer

    cheControl

    egory

    arset

    ar

    entCertificate

    dePage

    umn

    ntentsApplication

    Session

    ntentType

    okies

    Request

    Response

    ntents.RemoveApplication

    Session

    Contents.RemoveAll Application

    Session

    CreateObject

    Description

    End

    Execute

    Expires

    ExpiresAbsolute

    File

    Flush

    Form

    GetLastError

    HTMLEncode

    IsClientConnected

    LCID

    Line

    MapPath

    Number

    ObjectContext

    OnEnd

    Application

    Session

    OnStart Application

    Session

    OnTransactionAbort

    OnTransactionCommit

    Pics

    QueryString

    Redirect

    Request

    Response

    ScriptTimeout

    Server

    ServerVariables

    Session

    SessionID

    SetAbort

    SetComplete

    Source

    StaticObjects Application

    Session

    Status

    Timeout

    Transfer

    URLEncode

    Write

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 8/8/2019 DevGuru ASP Quickref

    10/85

    ETHOD: Session.Abandon

    ssion.Abandon

    e Abandon method terminates a user session, destroys all the objects in the current

    ssion object, and releases its resources. However, this deletion will not occur until all of the

    ript is processed for the current page. When the session ends, the OnEnd event handler is

    led. By default, even if you do not call Abandon, the Session object is terminated after

    enty minutes of idle time.

    de:

    ------------File1.asp-------------------%

    sponse.Write "Your SessionID is " & Session.SessionIDssion("Application") = "DevSite"ssion.Abandon

    sponse.Write "The Application name is " & Session("Application")>

    ------------File2.asp---------------------

    %sponse.Write "Your SessionID is " & Session.SessionID

    >

    tput:--------File1.asp-------------------------

    ur SessionID is 465107831e Application name is DevSite

    -------File2.asp--------------------------

    ur SessionID is 465107831

  • 8/8/2019 DevGuru ASP Quickref

    11/85

    ETHOD: Response.AddHeader

    sponse.AddHeaderName, Value

    e AddHeader method adds a new named HTTP header with a specific value to the HTTP

    sponse. Note that once a header has been added, it cannot be removed. This method must

    called before any output is sent to the client unless the Response.Buffer is set to true.

    ere are two mandatory arguments.

    me

    e Name argument is the name of the new header variable. The name cannot contain any

    derscores ( _ ).

    lue

    e Value argument is the initial value of the new header variable.

    de:

    %sponse.AddHeader "MyHeader", "ERROR"

    >

  • 8/8/2019 DevGuru ASP Quickref

    12/85

    ETHOD: Response.AppendToLog

    sponse.AppendToLog(String)

    e AppendToLog method adds (appends) a string to the end of the entry of the Web server

    for this request.

    ere is one mandatory argument.

    ring

    e String argument is the string to be appended. The string can have a maximum length of

    characters. It cannot contain commas because the log is comma-delineated.

    de:%

    sponse.AppendToLog("Error in Processing")>

    tput is appended to the end of the IIS log file:

    .78.176.37, - , 03/20/97, 7:55:20, W3SVC, SALES1, 10.78.176.37, Error in Processing

  • 8/8/2019 DevGuru ASP Quickref

    13/85

    BJECT: Application

    odified in version 3.0

    e Application object shares, stores, and retrieves information in response to requests from

    ers to the application.

    OLLECTION PROPERTIES

    ontents Object

    collection of all of the items which have been created and added to the Application object

    ring client sessions through script commands, such as the Server.CreateObject, rather than

    using the HTML tag.

    aticObjects Object

    collection of all of the items which have been created and added to the Application object

    ring client sessions by using the HTML tag, rather than using script commands.

    ETHODS

    ontents.Remove Method Implemented in version 3.0e Contents.Remove method is used to remove a single item from a Contents collection.

    ontents.RemoveAll Method Implemented in version 3.0

    e Contents.RemoveAll method is used to remove all items from a Contents collection.

    ck Method

    e Lock method prevents all other users from making changes in the Application object.

    lock Method

    e Unlock method allows any user to have access to any of the Application object

    operties in order to make changes.

    VENTS

    nEnd Event

    e OnEnd event occurs when the Application quits. This should not occur unless all user

    ssions are over. The signal of this event will run a handler script in the Global.asa file, if theript exist.

    nStart Event

    e OnStart event occurs before the start of any new session by a user (i.e., before the

    pplication object is first referenced). The signal of this event will run a handler script in the

    obal.asa file, if the script exist.

  • 8/8/2019 DevGuru ASP Quickref

    14/85

    OLLECTION PROPERTY: Application.Contents

    pplication.Contents(Key)

    e Contents collection property contains a list of the items that have been created and added

    the Application object. Objects can be added to the collection by using Server.CreateObject

    by assigning scalar variables.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    y

    e Key argument is the name of the item to be retrieved.

    de:%

    plication("name") = "Application Maker"

    plication("publishdate") = "05/15/01"

    plication("author") = "DevGuru"t Application("Obj1") = Server.CreateObject("ADODB.Connection")

    r Each Item in Application.ContentsIf IsObject(Application.Contents(Item)) ThenResponse.Write Item & " is an object.
    "

    ElseResponse.Write Item & "=" & Application.Contents(Item) & "
    "

    End Ifxt

    >

    tput:me=Application Makerblishdate=05/15/01thor=DevGuru

    BJ1 is an object.

  • 8/8/2019 DevGuru ASP Quickref

    15/85

    OLLECTION PROPERTY: Application.StaticObjects

    pplication.StaticObjects(Key)

    e StaticObjects collection property is a collection that contains of all of the items created

    hin the Application using the HTML tag. You can use this collection to find the

    ue of any property for any object.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    y

    e Key argument is the name of the item to be retrieved.

    de:------Global.asa-------------

    OBJECT RUNAT=Server SCOPE=Application ID=MyInfo PROGID="MSWC.MyInfo">

    OBJECT>

    OBJECT RUNAT=Server SCOPE=Application ID=MyConnectionROGID="ADODB.Connection">OBJECT>

    OBJECT RUNAT=Server SCOPE=Application ID=MyADRot PROGID="MSWC.ADRotator">OBJECT>

    -------File.asp-----------------%

    r Each Item In Application.StaticObjectssponse.Write Item & "
    "

    xt>

    tput:yInfoyConnectionyADRot

  • 8/8/2019 DevGuru ASP Quickref

    16/85

    ETHOD: Application.Contents.Remove

    plemented in version 3.0

    pplication.Contents.Remove (Name|Integer)

    e Contents.Remove method is used to delete one specified item in the

    pplication.Contents collection.

    u may use only one of the two possible choices for the mandatory argument.

    me or Integer

    e Name argument is the name of the item to be deleted. It must be enclosed in a pair of

    otes.

    e Integer argument is the position number of the item in the collection to be deleted. The

    mbering sequence for a collection starts at one, not zero.

    de:

    %plication("name") = "Application Maker"plication("publishdate") = "05/15/01"plication("author") = "DevGuru"

    t Application("Obj1") = Server.CreateObject("ADODB.Connection")

    plication.Contents.Remove(1)plication.Contents.Remove("publishdate")

    r Each Item in Application.ContentsIf IsObject(Application.Contents(Item)) Then

    Response.Write Item & " is an object.
    "

    ElseResponse.Write Item & "=" &Application.Contents(Item) & "
    "

    End If

    xt>

    tput:thor=DevGuru

    bj1 is an object.

  • 8/8/2019 DevGuru ASP Quickref

    17/85

    ETHOD: Application.Contents.RemoveAll

    plemented in version 3.0

    pplication.Contents.RemoveAll

    e Contents.RemoveAll method deletes all items that are in the Application.Contents

    lection.

    member to include the pair of empty ( ).

    de:%

    plication.Contents.RemoveAll( )

    >

  • 8/8/2019 DevGuru ASP Quickref

    18/85

    ETHOD: Application.Lock

    pplication.Lock

    e Lock method prevents all other users from changing any of the variables in the Contents

    lection of the Application object.

    pplication objects are designed to be shared among an unlimited number of users.

    erefore, you need the ability to allow only one user at a time to make changes and you dos by locking everybody else out.

    u can use the Unlock method to explicitly remove the Lock placed upon the Application

    ect. Remember, to completely unlock an object, you must call Unlock the same number of

    es you have called Lock. Fortunately, the server will automatically unlock all locks placed

    the object when the script times out or the .asp file ends.

    de:

    %plication.Lock

    >

  • 8/8/2019 DevGuru ASP Quickref

    19/85

    ETHOD: Application.Unlock

    pplication.Unlock

    e Unlock method is used to explicitly unlock the variables in the Contents collection of the

    pplication object.

    contrast, the Lock method prevents all other users from changing any of the variables in the

    ontents collection of the Application object. This ability to lock is required since Applicationects are designed to be shared among an unlimited number of users. Therefore, you need

    e ability to allow only one user at a time to make changes and you do this by locking

    erybody else out.

    member, to completely unlock an object, you must call Unlock the same number of times

    u have called Lock. Fortunately, the server will automatically unlock all locks placed on the

    ect when the script times out or the .asp file ends.

    de:%

    plication.Unlock

    >

  • 8/8/2019 DevGuru ASP Quickref

    20/85

    VENT: Application_OnEnd

    e Application_OnEnd event occurs when the Application ends. This should only happen

    en the web server is stopped by the operating system in a normal manner. The

    pplication_OnEnd event is simply a subroutine with a reserved name that is placed within

    e Global.asa file. It can contain any script that you wish to run after all user sessions areshed. For example, you may wish to compute and store statistics on user sessions for futureerence.

    te: The only built-in ASP objects available from within the OnEnd event handler are Server

    d Application.

    de:---------------Global.asa--------------------------cript Language="VBScript" RUNAT=Server>

    b Application_OnEnd()Calculate_Stats()d Sub

    b Application_OnStart()Application("NumSession") = 0

    Application("NumVisited") = 0d Sub

    b Session_OnEnd()Application("NumSession") = Application("NumSession") - 1

    d Sub

    b Session_OnStart()Application("NumSession") = Application("NumSession") + 1Application("NumVisited") = Application("NumVisited") + 1d Sub

    script>

    ---------------File1.asp----------------------------sponse.Write "You are " & Application("NumSession") & " of " & Application("NumVisited") &sers."

  • 8/8/2019 DevGuru ASP Quickref

    21/85

    VENT: Application_OnStart

    e Application_OnStart event occurs before the beginning of any user session. The only

    lt-in ASP objects available from within the OnStart event handler are Server and Application.e Application_OnStart event is simply a subroutine with a reserved name that is placed

    hin the Global.asa file. It contains any script that you wish to run before the first userssion. For example, you could use the Session.Timeout property to automatically end an

    e user session after 10 minutes.

    te that you must declare the scripting language used to code the event script on the first line

    the Global.asa file.

    de:---------------Global.asa--------------------------cript Language="VBScript" RUNAT=Server>b Application_OnEnd()

    d Sub

    b Application_OnStart()Application("NumSession") = 0

    Application("NumVisited") = 0Session.Timeout = 10d Sub

    b Session_OnEnd()Application("NumSession") = Application("NumSession") - 1d Sub

    b Session_OnStart()Application("NumSession") = Application("NumSession") + 1Application("NumVisited") = Application("NumVisited") + 1d Sub

    script>

    ---------------File1.asp----------------------------sponse.Write "You are " & Application("NumSession") & " of " & Application("NumVisited") &sers."

    tput:u are 1 of 1 users.

  • 8/8/2019 DevGuru ASP Quickref

    22/85

    BJECT: ASPError

    plemented in version 3.0

    e ASPError object is used to obtain detailed information on an error condition. This

    ormation, provided by the nine read-only properties of ASPError, can only be accessed by

    ng the Server.GetLastError method.

    ROPERTIES

    SPCode Property

    e ASPCode property returns the error code generated by IIS.

    SPDescription Property

    e ASPDescription property returns a string that provides more detailed description of the

    or as compared to the short description returned by the Description property. (Not available

    all errors.)

    tegory Property

    e Category property returns a string indicating if the error was generated by IIS, an object,

    a scripting language.

    olumn Property

    e Column property returns a long integer defining the column position inside the ASP file

    ere the error occurred.

    scription Property

    e Description property returns a string that is a short description of the error. If you desire a

    ger description, use the ASPDescription property.

    e Property

    e File property returns the name of the ASP (Active Server Page) file in which the error

    curred.

    ne Property

    e Line property returns an long integer defining the line number inside the ASP file where

    e error occurred.

    mber Property

    e Number property returns a long integer defining the standard COM error code returned by

    COM component.

    urce Property

    e Source property returns a string with the actual line from the source code where the error

    curred (if available).

  • 8/8/2019 DevGuru ASP Quickref

    23/85

    ETHOD: Server.GetLastError

    plemented in version 3.0

    rver.GetLastError( )

    e GetLastError method returns an instance of the ASPError object. The ASPError object

    poses (gives access to) nine read-only properties that provide detailed information about an

    or that has occurred.

    ce an ASP file has sent content to a client, you cannot use the GetLastError method to

    cess information about the error.

    e types of errors handled by the ASPError method are called "500;100 custom errors" and

    ere are three major types: pre-processing, runtime, and script compiling.

    default, the error information is sent to the "\iishelp\common\500-100.asp" file. This is a newthat is part of IIS version 5.0 and does not exist in earlier versions. Here is the source code

    the 500-100.asp file. Since you can access this file, you can customize this code to suit

    ur programming needs.

    so, you can create your own personal, custom ASP error file by having the Internetormation Server (IIS) 5.0 redirect the 500;100 custom errors to an error file that you create.your ASP error file, you can run any ASP code you desire.

    re is the general concept of how to access the nine ASPError properties in an error file

    de:%m objErrorInfo

    t objErrorInfo = Server.GetLastError

    sponse.Write("ASPCode = " & objErrorInfo.ASPCode)sponse.Write("ASPDescription = " & objErrorInfo.ASPDescription)sponse.Write("Category = " & objErrorInfo.Category)

    sponse.Write("Column = " & objErrorInfo.Column)sponse.Write("Description = " & objErrorInfo.Description)sponse.Write("File = " & objErrorInfo.File)sponse.Write("Line = " & objErrorInfo.Line)sponse.Write("Number = " & objErrorInfo.Number)

    sponse.Write("Source = " & objErrorInfo.Source)

    >

  • 8/8/2019 DevGuru ASP Quickref

    24/85

    he source code for the 500-100.asp file:s presented to demonstrate how Microsoft programmers use the ASPError object to display errors. Cert

    rts of the code have been colorized to call your attention to specific procedures.

    %@ language="VBScript" %>%ption Explicit

    onst lngMaxFormBytes = 200

    m objASPError, blnErrorWritten, strServername, strServerIP, strRemoteIPm strMethod, lngPos, datNow, strQueryString, strURL

    Response.Buffer Thenesponse.Clearesponse.Status = "500 Internal Server Error"

    esponse.ContentType = "text/html"esponse.Expires = 0nd If

    et objASPError = Server.GetLastError>DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

    tml dir=ltr>

    ead>

    tyle>ink {font:8pt/11pt verdana; color:FF0000}visited {font:8pt/11pt verdana; color:#4e4e4e}style>

    META NAME="ROBOTS" CONTENT="NOINDEX">

    tle>The page cannot be displayed

    META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">head>

    cript>nction Homepage(){--n real bits, urls get returned to our script like this:res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm

    For testing use DocURL =es://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm"ocURL=document.URL;

  • 8/8/2019 DevGuru ASP Quickref

    25/85

    his is where the http or https will be, as found by searching for :// but skipping the res://otocolIndex=DocURL.indexOf("://",4);

    his finds the ending slash for the domain serverrverIndex=DocURL.indexOf("/",protocolIndex + 3);

    or the href, we need a valid URL to the domain. We search for the # symbol to find the beginingf the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker.

    urlresult=DocURL.substring(protocolIndex - 4,serverIndex);eginURL=DocURL.indexOf("#",1) + 1;result=DocURL.substring(BeginURL,serverIndex);

    or display, we need to skip after http://, and go to the next slashsplayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);cument.write('' + displayresult + "");

    ->script>

    ody bgcolor="FFFFFF">

    able width="410" cellpadding="3" cellspacing="5">

    r>d align="left" valign="middle" width="360">1 style="COLOR:000000; FONT: 13pt/15pt verdana">The page cannot be displayedtd>tr>

    r>

    d width="400" colspan="2">ont style="COLOR:000000; FONT: 8pt/11pt verdana">There is a problem with the page you are trying toach and it cannot be displayed.tr>

    r>d width="400" colspan="2">ont style="COLOR:000000; FONT: 8pt/11pt verdana">

    r color="#C0C0C0" noshade>

    >Please try the following:

    l>id="instructionsText1">Click the

    a href="javascript:location.reload()">efresh button, or try again later.
    i>

    >Open the

    cript>

  • 8/8/2019 DevGuru ASP Quickref

    26/85

    --!((window.navigator.userAgent.indexOf("MSIE") > 0) && (window.navigator.appVersion.charAt(0) == "2")

    omepage();

    ->script>

    me page, and then look for links to the information you want.

    ul>

    2 style="font:8pt/11pt verdana; color:000000">HTTP 500.100 - Internal Server Error - ASP error
    ernet Information Services

    r color="#C0C0C0" noshade>

    >Technical Information (for support personnel)

    l>

    >Error Type:
    %esponse.Write objASPError.CategoryobjASPError.ASPCode > "" Then Response.Write ", " & objASPError.ASPCodeesponse.Write " (0x" & Hex(objASPError.Number) & ")" & "
    "

    esponse.Write "" & objASPError.Description& "
    "

    objASPError.ASPDescription > "" Then Response.Write objASPError.ASPDescription & "
    "

    nErrorWritten = False

    Only show the Source if it is available and the request is from the same machine as IISobjASPError.Source > "" ThenServername = LCase(Request.ServerVariables("SERVER_NAME"))ServerIP = Request.ServerVariables("LOCAL_ADDR")RemoteIP = Request.ServerVariables("REMOTE_ADDR")(strServername = "localhost" Or strServerIP = strRemoteIP) And objASPError.File> "?" Thenesponse.Write objASPError.FileobjASPError.Line > 0 Then Response.Write ", line " & objASPError.LineobjASPError.Column > 0 Then Response.Write ", column " & objASPError.Column

    esponse.Write "
    "esponse.Write ""

    esponse.Write Server.HTMLEncode(objASPError.Source) & "
    "objASPError.Column > 0 Then Response.Write String((objASPError.Column - 1), "-")"^
    "esponse.Write ""nErrorWritten = Truend Ifnd If

  • 8/8/2019 DevGuru ASP Quickref

    27/85

    Not blnErrorWritten And objASPError.File "?" Thenesponse.Write "" & objASPError.FileobjASPError.Line > 0 Then Response.Write ", line " & objASPError.LineobjASPError.Column> 0 Then Response.Write ", column " & objASPError.Columnesponse.Write "
    "nd If>i>

    p>>Browser Type:

    %= Request.ServerVariables("HTTP_USER_AGENT") %>i>

    p>>Page:

    %Method = Request.ServerVariables("REQUEST_METHOD")

    esponse.Write strMethod & " "

    strMethod = "POST" Thenesponse.Write Request.TotalBytes & " bytes to "nd If

    esponse.Write Request.ServerVariables("SCRIPT_NAME")

    gPos = InStr(Request.QueryString, "|")

    ngPos > 1 Thenesponse.Write "?" & Left(Request.QueryString, (lngPos - 1))nd If

    esponse.Write ""

    strMethod = "POST" Then

    esponse.Write "

    POST Data:
    "Request.TotalBytes > lngMaxFormBytes Thenesponse.Write Server.HTMLEncode(Left(Request.Form, lngMaxFormBytes)) & " . . ."seesponse.Write Server.HTMLEncode(Request.Form)nd If

    esponse.Write ""nd If

    >p>>Time:

    %tNow = Now()

    esponse.Write FormatDateTime(datNow, 1) & ", " & FormatDateTime(datNow, 3)

  • 8/8/2019 DevGuru ASP Quickref

    28/85

    >i>p>

    p>>More information:

    % strQueryString = "prd=iis&sbp=&pver=5.0&ID=500;100&cat=" &

    erver.URLEncode(objASPError.Category) & _os=&over=&hrd=&Opt1=" & Server.URLEncode(objASPError.ASPCode) & "&Opt2=" &

    erver.URLEncode(objASPError.Number) & _Opt3=" & Server.URLEncode(objASPError.Description)URL = "http://www.microsoft.com/ContentRedirect.asp?" & _QueryString>

    a href="">Microsoft Supporti>p>

    font>tr>

    able>body>html>

  • 8/8/2019 DevGuru ASP Quickref

    29/85

    ETHOD: Request.BinaryRead

    quest.BinaryRead(Count)

    e BinaryRead method retrieves the unparsed data that was sent to the server from the user

    part of an HTTP POST (i.e. an HTML FORM request). The data read is stored in a

    feArray which is a variant, structure-like array that, in addition to storing the data, also storese number of dimensions of the array and the upper bounds of those dimensions.

    u can write binary data into the response stream (info sent to a client) by using the

    sponse.BinaryWrite(BinaryData) method. The BinaryData argument is simply the output

    e SafeArray) from Request.BinaryRead. For example, you could retrieve an image from a

    tabase with Request.BinaryRead and send it to a client using Response.BinaryWrite.

    ing Request.Form after calling BinaryRead, and vice-versa, will cause an error.

    ere is one mandatory argument.

    ount

    fore the method is executed, Count contains the number of bytes to be read. After theethod has returned, Count contains the actual number of bytes read. The number read

    ould be less than or equal to the total byte count value returned by Request.TotalByte.

    de:%m ByteCount, BinReadteCount = Request.TotalBytes

    nRead = Request.BinaryRead(ByteCount)

    sponse.BinaryWrite(BinRead)>

  • 8/8/2019 DevGuru ASP Quickref

    30/85

    ETHOD: Response.BinaryWrite

    sponse.BinaryWrite(Data)

    e BinaryWrite method writes nonstring data (binary data) to the current HTTP output

    hout any character set conversion.

    is method can use the output of the Request.BinaryRead method. For example, you could

    rieve an image from a database with Request.BinaryRead and send it to a client usingsponse.BinaryWrite.

    ere is one mandatory argument.

    ta

    e Data argument is the data to send to the HTTP output.

    de:---------------File1.asp------------------

    TML>

    EAD>HEAD>ODY>

    orm action="File2.asp" method="POST">me:
    e:
    x:
    put type="Submit" name="submit" value="submit">

    orm>BODY>HTML>

    ---------------File2.asp------------------%tecount = Request.TotalBytesread = Request.BinaryRead(bytecount)sponse.BinaryWrite binread

    >

    tput:me=Jane&age=25&Sex=Female&submit=submit

  • 8/8/2019 DevGuru ASP Quickref

    31/85

    ROPERTY: Response.Buffer

    odified in version 3.0

    e Buffer property tells whether to buffer (temporarily store) the output page being sent to the

    owser. A response is not sent to the browser until all scripts are processed, or the Flush or

    d methods are called. The Buffer property cannot be set or changed after the server has

    nt output to the browser. Therefore, you need to set the Buffer property on the first line of

    e ASP page. If the Buffer is set to True, then the server will buffer the output. If it is set tolse, then no buffering occurs.

    ASP version 2.0 the default value is False and no buffering is done.

    ASP version 3.0 the default value is True and the server will buffer the output. However,

    ere is a quirk concerning the default value of Response.Buffer that is dependent upon how

    ndows 2000 (which contains IIS 5.0 and ASP 3.0) is initially installed on your computer. Ifu do a clean install, the default value will be True. If the install is an upgrade, the default

    ue will be False.

    the code example, there is no output because the loop does not finish and the Buffer will not

    mpty until the script has finished. If the buffer was set to False, then the Response.Writeuld write the number to the browser every time it went through the loop.

    de:%

    sponse.Buffer = TRUE0

    x = x+1Response.Write x & "
    "

    op

    >

  • 8/8/2019 DevGuru ASP Quickref

    32/85

    ROPERTY: Response.CacheControl

    e CacheControl property allows a proxy server to cache an Actice Server Page. A proxy

    rver is used to speed up the retrieval of a web page by keeping a local copy of the web pagea cache.

    e CacheControl property can only be set equal to "Public" or "Private". The pair of double

    otes are required.

    he CacheControl property is set equal to "Public", then caching can occur.

    he CacheControl property is set equal to "Private", then caching cannot occur. By default,

    proxy server will not keep a cache copy.

    u can use Response.Expires and Response.ExpiresAbsolute to set a time and/or date

    it on the existence of the cache.

    % Response.CacheControl = "Public" %>

    % Response.CacheControl = "Private" %>

  • 8/8/2019 DevGuru ASP Quickref

    33/85

    ROPERTY: Response.Charset

    e Charset property adds the name of the character set to the content-type header contained

    the response object. Unfortunately, CharSet will accept any string, vaild or not, for the name.

    e default character set is ISO-LATIN-1, except on the Macintosh where the default is the

    acintosh character set.

    the example, if the header is:

    ntent-type: text/html

    en the header will become:ntent-type: text/html; charset = MS_Kanji

    de:

    % Response.Charset("MS_Kanji") %>

  • 8/8/2019 DevGuru ASP Quickref

    34/85

    ETHOD: Response.Clear

    sponse.Clear

    e Clear method clears (erases) any buffered HTML output. It does not erase the response

    aders, only the body. If the buffer does not exist, because Response.Buffer was set to

    lse, a runtime error will occur.

    te that in ASP version 2.0, the default for Response.Buffer is set to False, however in ASPrsion 3.0, the default for Response.Buffer is set to True.

    de:

    %sponse.Clear

    >

  • 8/8/2019 DevGuru ASP Quickref

    35/85

    OLLECTION PROPERTY: Request.ClientCertificate

    quest.ClientCertificate(Key [SubField])

    e procedure for maintaining security in electronic transactions is to use the Secure Socketyers (SSL) protocol. If in use by the browser, this protocol sends certificates to the serverat identifies the browser. The ClientCertificate collection property retrieves the values of

    ese client certification fields. An interesting feature of this protocol is the use of the https://

    efix rather than the normal http://.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    y

    e Key argument is a string that specifies the name of the field to retrieve. Note the use of the

    uble quotes in the code example. A certificate contains the following seven fields:

    Certificate. A string containing the binary stream of the entire certificate

    content.

    Flags. There are two flags that provide additional client certificate information.

    The ceCertPresent flag indicates a client certificate is present. The

    ceUnrecognizedIssuer flag indicates the last certification in this chain is from

    an unknown user.

    Issuer is a string containing the subfield values that provide information about

    the issuer of the certificate.

    SerialNumber is a string that contains the certification serial number.

    Subject is a string containing the subfield values that provide information aboutthe subject of the certificate.

    ValidFrom is the date when the certificate becomes valid.

    ValidUntil is the expiration date of the certificate.

    bfield

    e optional Subfield argument is used only with the Issuer or the Subject key fields. It is

    ded to the key field as a suffix. For example, IssuerL which is the locality of the Issuer. Or,

    bjectCN which gives the common name of the user.

    e allowed values are:

    C is the name of the country of origin.

    CN is the common name of the user.

    GN is a given name.

    I is a set of initials.

    L is a locality.

    O is the company or organization name.

    OU is the name of the organizational unit.

  • 8/8/2019 DevGuru ASP Quickref

    36/85

    S is a state or province.

    T is the title of the person or organization.

    de:

    TML>EAD>

    HEAD>ODY>is certification is valid from until .BODY>HTML>

    tput:

    is certification is valid from 9/26/96 11:59:59 PM until 9/26/97 11:59:59 PM.

  • 8/8/2019 DevGuru ASP Quickref

    37/85

    ROPERTY: Session.CodePage

    e CodePage property specifies which server codepage to use when displaying dynamic

    tive Server Pages. A codepage is a character set used for symbol mapping. The defaultue of the CodePage varies by location and language. If you specify a new CodePage

    operty, it will exist only for the duration of the session.

    de:

    % @CodePage = 437ave orginal codepage information

    ssion("CodePage") = Session.CodePage

    D is the CodePage ID from form andext is the text entered in the Form

    = Request.Form("ID")xt = Request.Form("ToTranslate")

    ook up text in specified language. The function FindTranslation

    oes the work of finding the translation.ssion.CodePage = IDnslation = FindTranslation(text, ID)

    hange CodePage in order to write in English then change

    again to write in specified language

    ranslation "" ThenSession.CodePage = Session("CodePage")Response.Write "The translation of " & text & " is "

    Session.CodePage = IDResponse.Write translation

    d If>

  • 8/8/2019 DevGuru ASP Quickref

    38/85

    OLLECTION PROPERTY: Session.Contents

    ssion.Contents(Key)

    e Contents collection property contains a list of all of the items that has been created and

    ded to the Session object through script commands, rather than by using the HTML

    OBJECT> tag.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    y

    e key argument is the name of the item to retrieve.

    de:%

    ssion("name") = "Application Maker"

    ssion("publishdate") = "05/01/99"

    ssion("author") = "ISSI"t Session("Obj1") = Server.CreateObject("ADODB.Connection")

    r Each Item in Session.ContentsIf IsObject( Session.Contents(Item)) ThenResponse.Write Item & " is an object.
    "

    ElseResponse.Write Item & "=" & Session.Contents(Item) & "
    "

    End Ifxt

    >

    tput:AME=Application MakerUBLISHDATE=05/01/99UTHOR=ISSI

    BJ1 is an object.

  • 8/8/2019 DevGuru ASP Quickref

    39/85

    ROPERTY: Response.ContentType

    e ContentType property specifies the HTTP content type, which includes a type/subtype, for

    e response header. The type is the general content, and the subtype is the specific content.e default is text/HTML.

    is example code will produce a 2 X 2 Excel Spreadsheet in a browser, if Excel is installed on

    e client machine.

    de:% Response.ContentType = "application/vnd.ms-excel" %>

    TML>

    EAD>HEAD>ODY>ABLE>

    R>D>2D>4

    TR>R>

    D>5D>6

    TR>TABLE>

    BODY>

    HTML>

  • 8/8/2019 DevGuru ASP Quickref

    40/85

    OLLECTION PROPERTY: Request.Cookies

    quest.Cookies(Name)[(Key)|.Attribute]

    e Cookies collection property allows you to access the values of the browser cookies sent in

    requests.

    ere is one mandatory argument.

    me

    e Name argument specifies the name of the cookie to be retrieved.

    ere are two optional arguments.

    y

    e Key argument specifies which value from the cookie dictionary to retrieve.

    tribute

    e optional Attribute argument is the boolean variable HasKeys.

    ue indicates that the cookie contains keys.lse indicates that the cookie does not contains keys

    u can iterate through a collection using a For Each ... Next loop.

    de:%

    r Each objCK In Request.CookiesResponse.Write objCK & " = " & Request.Cookies(objCK) & "
    "xt

    >

    tput:RD2 = VBScriptRD1 = ASP

    AIN = DevSite

  • 8/8/2019 DevGuru ASP Quickref

    41/85

    OLLECTION PROPERTY Response.Cookies

    sponse.Cookies(Name)[(Key)|.Attribute] =Value

    e Cookies collection property assignes a new value to a cookie, if it exists; otherwise, the

    okie is created and the value is assigned.

    ere are two mandatory arguments.

    me

    e Name argument is the name of the cookie.

    lue

    e Value argument specifies the value to assign to the key or attribute.

    ere are two optional arguments.

    tribute

    e optional Attribute argument can one of the five following parameters:

    Domain is write-only and allows pages on a domain made up of more than one

    server to share cookie information.

    Expires is write-only and is the date on which the cookie expires. Unless a date

    is specified, the cookie will expire when the session ends. If a date is specified,the cookie will be stored on the client's disk after the session ends.

    HasKeys is read-only and uses Boolean values to specify whether the cookie

    contains keys.

    Path is write-only and if set, the cookie is sent by this path. If this argument is

    not set, the default is the application path.

    Secure is write-only and indicates if the cookie is secure.

    y

    e optional Key argument specifies the Key to which the Value is assigned.

    de:

    %sponse.Cookies("myProduct")("Main") = "DevSite"sponse.Cookies("myProduct")("Prd1") = "ASP"sponse.Cookies("myProduct")("Prd2") = "VBScript"

    sponse.Write Request.Cookies("myProduct")>

    tput:RD2=VBScript&PRD1=ASP&MAIN=DevSite

  • 8/8/2019 DevGuru ASP Quickref

    42/85

    ETHOD: Session.Contents.Remove

    plemented in version 3.0

    ssion.Contents.Remove (Name|Integer)

    e Contents.Remove method is used to delete one specified item in the Session.Contents

    lection.

    u may use only one of the two possible choices for the mandatory argument.

    me or Integer

    e Name argument is the name of the item to be deleted. It must be enclosed in a pair of

    otes.

    e Integer argument is the position number of the item in the collection to be deleted. The

    mbering sequence for a collection starts at one, not zero.

    de:

    %ssion("name") = "Session Maker"ssion("publishdate") = "05/15/01"ssion("author") = "DevGuru"t Session("Obj1") = Server.CreateObject("ADODB.Connection")

    ssion.Contents.Remove(1)ssion.Contents.Remove("publishdate")

    r Each Item in Session.ContentsIf IsObject(Session.Contents(Item)) Then

    Response.Write Item & " is an object.
    "

    ElseResponse.Write Item & "=" &Session.Contents(Item) & "
    "

    End If

    xt>

    tput:thor=DevGuru

    bj1 is an object.

  • 8/8/2019 DevGuru ASP Quickref

    43/85

    ETHOD: Session.Contents.RemoveAll

    plemented in version 3.0

    ssion.Contents.RemoveAll

    e Contents.RemoveAll method deletes all items that are in the Session.Contents

    lection.

    member to include the pair of empty ( ).

    de:%

    ssion.Contents.RemoveAll( )

    >

  • 8/8/2019 DevGuru ASP Quickref

    44/85

    ETHOD: Server.CreateObject

    rver.CreateObject(ObjectID)

    e CreateObject method is probably the most widely used and the most important method

    ailable through the Built-in Actice Server Pages Objects. It allows you to instantiate the

    mponents of a script, or in different terms, create an instance of other objects. As a directnsequence, you can use and access any collections, events, methods, and properties

    sociated with these objects.

    ere is one mandatory argument.

    bjectID

    e ObjectID argument specifies the type of object to be created.

    e following code creates a connection to a database:

    de:

    % Set myconn = Server.CreateObject("ADODB.Connection") %>

  • 8/8/2019 DevGuru ASP Quickref

    45/85

    ETHOD: Response.End

    sponse.End

    e End method orders the web server to stop processing the script. The current results are

    urned and no further processing occurs. If Response.Buffer is set to True, Response.End

    l flush the buffer and then end.

    te that in ASP version 2.0, the default for Response.Buffer is set to False, however in ASPrsion 3.0, the default for Response.Buffer is set to True.

    the example, the second Response.Write will not be displayed in the output.

    de:%

    sponse.Write "Hello World"sponse.End

    sponse.Write "Is this the End?">

    tput:llo World

  • 8/8/2019 DevGuru ASP Quickref

    46/85

    ETHOD: Server.Execute

    plemented in version 3.0

    rver.Execute(Path)

    e Execute method allows you to call another ASP page from inside an ASP page. When the

    led ASP page completes its tasks, you are then returned to the calling ASP page. The

    erall effect is very similar to a function or subroutine call. Any text or output from the calledP page will be displayed on the calling ASP page. The Execute method is a more useful

    ernative to using server-side includes.

    contrast, the Transfer method allows you to transfer from one ASP page to another without

    urning to the calling ASP page.

    ere is one mandatory argument.

    th

    e Path argument is a string specifying either the absolute or relative path of the ASP page

    ng called. The file name must be included in the path. The entire Path must be enclosedide a pair of quotes. The Path argument cannot include a query string, however, any query

    ng that was available to the calling ASP page will be available to the called ASP page.

    de:------CallingAsp.asp----------TML>ODY>

    w now cow?

    BODY>

    HTML>

    ------CalledAsp.asp----------%

    sponse.Write "pink">

    tput:w now pink cow?

  • 8/8/2019 DevGuru ASP Quickref

    47/85

    ROPERTY: Response.Expires

    e Expires property specifies a length of time in minutes before a response page cached on

    e browser expires.

    e first line of code causes the page to be refreshed (reloaded) every time it is accessed,her than being stored in a cache.

    the second example, if the user returns to this page before the 15 minutes are up, theched version of the page will be displayed.

    % Response.Expires = 0 %>

    % Response.Expires = 15 %>

  • 8/8/2019 DevGuru ASP Quickref

    48/85

    ROPERTY: Response.ExpiresAbsolute

    e ExpiresAbsolute property sets the precise date and time when a response page cached

    the browser will expire. If the time is not given, then the page will expire exactly at midnightthe given date. If the date is not given, then the page will expire at the given time on the

    me day that the script is run.

    e following code specifies that the page will expire at 6:00 PM on May 15th of 1999. You

    ust use a 24 hour clock for the time and four digits for the year.

    % Response.ExpiresAbsolute=#May 15, 1999 18:00:00# %>

  • 8/8/2019 DevGuru ASP Quickref

    49/85

    ETHOD: Response.Flush

    sponse.Flush

    e Flush method immediately sends all current buffered page content to the client if the

    sponse.Buffer property is set to True.

    he buffer does not exist, because Response.Buffer is set to False, a runtime error will

    cur.

    te that in ASP version 2.0, the default for Response.Buffer is set to False, however in ASP

    rsion 3.0, the default for Response.Buffer is set to True.

    de:%

    sponse.Flush>

  • 8/8/2019 DevGuru ASP Quickref

    50/85

    OLLECTION PROPERTY: Request.Form

    quest.Form(Element)[(Index)|.Count]

    e FORM collection property contains, and allows you to retrieve, the values of the

    ements posted to a request form using the POST method.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    ement

    e Element argument is the name of the element which is used to retrieve a value.

    ere is one optional argument.

    dex

    e Index argument is used when the Element argument has more than one value. It is an

    eger, ranging from 1 to Request.Form(Element).Count , which is used to select values from element. Count is the total number of multiple values.

    de:---------------File1.asp------------------------

    TML>EAD>

    HEAD>ODY>

    orm action="File2.asp" method="POST">

    me:
    mpany:

    sition:
    dress:

    one:
    put type="Submit" name="Submit" value="Submit">orm>

    BODY>HTML>

    ---------------File2.asp------------------------TML>EAD>

    HEAD>

    ODY>

    % Response.Write Request.Form("Name")%> works for% Response.Write Request.Form("Company") %> at address% Response.Write Request.Form("Address") %> as a% Response.Write Request.Form("Position") %>.

    BODY>HTML>

    tput:

    ne Doe works for ISSI at address 5609 Kington Pike Knoville, TN as a Web Designer.

  • 8/8/2019 DevGuru ASP Quickref

    51/85

    ETHOD: Server.HTMLEncode

    rver.HTMLEncode(String)

    e HTMLEncode method applies HTML encoding syntax to a specified string of ASCII

    aracters. For example, this allows you to display a HTML tag on a web page and not have it

    ated as an actual tag.

    ere is one mandatory argument.

    ring

    e String argument is the string to be encoded.

    de:% Response.Write Server.HTMLEncode("The tag for a table is: ") %>

    tput:e tag for a table is:

    owser Output:e tag for a table is:

  • 8/8/2019 DevGuru ASP Quickref

    52/85

    ROPERTY: Response.IsClientConnected

    odified in version 3.0

    e IsClientConnected property determines if the client has disconnected from the server

    ce the last Response.Write. This property is particularly useful since it will prevent the

    rver from continuing to attempt to pass information after an unexpected disconnect.

    ASP 2.0, you must first attempt to pass information to the client in order to use this property.wever, in ASP 3.0 you can check the response of using this property before passing anyntent to the client. (Thus, a simple test will prevent the server from performing unneccesaryrk.)

    the example code, the output will be a list of all the book titles that are in the database.wever, if the user stops the connection to the server, then the only a partial list of titles willcreated.

    de:

    %t connDB=server.createobject("adodb.connection")

    nnDB.Open "books", "", ""ySQL="select * from books"t rsBookSrch = Server.CreateObject("ADODB.Recordset")

    BookSrch.Open mySQL, connDB, adOpenStatic, adLockPessimistic>TML>EAD>

    HEAD>ODY>

    %until (rsBookSrch.eof or Response.IsClientConnected=false)sponse.Write rsBookSrch.Fields("Title") %>

    % rsBookSrch.MoveNextopBookSrch.ClosennDB.Close

    >BODY>

    HTML>

  • 8/8/2019 DevGuru ASP Quickref

    53/85

    ROPERTY: Session.LCID

    e LCID property uses the location identifier number to access information on display format

    ues, such as currency, date, and time, that are specific to a location or region. The locationentifier number uniquely defines a geographic location or region. For example, the locationentifier number for France is 1036.

    de:

    %sponse.Write "This is the LCID for this page " & Session.LCID & "
    "sponse.Write "This is the Time and Date format for the above LCID: " & NOW() & "
    "

    ssion.LCID = 1033sponse.Write "This is the LCID for this page now " & Session.LCID & "
    "sponse.Write "This is the Time and Date format for the above LCID: " & NOW() & "
    "ssion.LCID = 3079

    >

    tput:is is the LCID for this page 1033

    is is the Time and Date format for the above LCID 5/12/99 10:01:33 PMis is the LCID for this page now 3079

    is is the Time and Date format for the above LCID 12.05.99 22:01:33

  • 8/8/2019 DevGuru ASP Quickref

    54/85

    ETHOD: Server.MapPath

    rver.MapPath(Path)

    e MapPath method maps a relative or virtual path to a physical path. This method does not

    eck for the validity or the existence of the physical path. If the path starts with a forward or

    ckward slash, the method returns the path as if the path is a full virtual path. If the path doest start with a slash, then the method returns the path relative to the directory of the ASP file

    ng processed.

    ere is one mandatory argument.

    th

    e Path argument is the path to be mapped.

    de:TML>

    EAD>HEAD>

    ODY>e path of this file is

    e path of the file1 is e path of the file2 is

    e path of the file3 is BODY>HTML>

    tput:e path of this file is D:\Inetpub\wwwroot\test.aspe path of the file1 is D:\Inetpub\wwwroot\test.aspe path of the file2 is D:\Inetpub\wwwroot\test\test.asp

    e path of the file3 is D:\Inetpub\wwwroot

  • 8/8/2019 DevGuru ASP Quickref

    55/85

    BJECT: ObjectContext

    e ObjectContext object is used to control Active Server Pages transactions which are

    anaged by the Microsoft Transaction Server (MTS). You may either complete (commit) orort a transaction.

    e @Transaction directive must be on the first line of the .asp file in order to use this object

    ee code examples). The @Transaction directive causes a transaction to run to completetion

    ess an abort occurs.

    ETHODS

    tAbort Method

    e SetAbort method declares that a transaction has not been completed and resources

    ould not be updated.

    tComplete Method

    e SetComplete method declares that the transaction has been completed and resources

    n be updated.

    VENTS

    nTransactionAbort Event

    e OnTransactionAbort event occurs when a transaction has been aborted for some kind of

    ocessing error. The signal of this event will run a handler script in the same file, if it exist.

    nTransactionCommit Event

    e OnTransactionCommit event occurs when a transaction has been successfully

    mpleted. The signal of this event will run a handler script in the same file, if it exist.

  • 8/8/2019 DevGuru ASP Quickref

    56/85

    ETHOD: ObjectContext.SetAbort

    bjectContext.SetAbort

    e SetAbort method explicity declares that a transaction has not been completed and

    events resources from being updated.

    t exists, the OnTransactionAbort event is processed.

    de:--------------------File1.asp-------------------TML>

    EAD>HEAD>ODY>

    orm action="File2.asp" method="POST">oductID:

    oduct Name:antity Wanted:put type="Submit" name="Submit" value="Submit">

    orm>BODY>HTML>

    --------------------File2.asp-------------------%

    Transaction = "Required"t connDB=server.createobject("adodb.connection")nnDB.Open "products", "", ""oductID = Request.Form("ProductID")

    ySQL="Select * from products Where productID = " & productID

    t rsProductSrch = Server.CreateObject("ADODB.Recordset")ProductSrch.Open mySQL, connDB, adOpenStatic, adLockPessimisticsProductSrch.BOF Or rsProductSrch.EOF ThenObjectContext.SetAbort

    seIf rsProductSrch.Fields("Quanity") < Request.Form("Order") ThenResponse.Write "There is not enough in stock to give the present order. There are " &ProductSrch.Fields("Quanity") & "in stock and your order is for " & Request.Form("Order") &br>"

    ObjectContext.SetAbortsersProductSrch.Fields("Quanity") = rsProductSrch.Fields("Quanity") -

    Request.Form("Order")

    rsProductSrch.UpdateObjectContext.SetCompleted If

    ProductSrch.ClosennDB.Close

    >

    b OnTransactionAborted()sponse.Write "The transaction aborted because there was not enough quantity on hand toyour order."

    d Sub

  • 8/8/2019 DevGuru ASP Quickref

    57/85

    b OnTransactionCommit()sponse.Write "The transaction was committed and your order is being sent."d Sub

    ere is no quantity of the desired product.tput:e transaction aborted because there was not enough quantity on hand to fill your order.

    ere is not enough of the desired product.

    tput:ere is not enough in stock to give the present order. There are 20 in stock and your order is25.

    e transaction aborted because there was not enough quantity on hand to fill your order.

  • 8/8/2019 DevGuru ASP Quickref

    58/85

    ETHOD: ObjectContext.SetComplete

    bjectContext.SetComplete

    e SetComplete method declares that the transaction of this object has been completed. In

    der for a transaction to be successfully completed, all individual components of the

    nsaction must also be completed and have called SetComplete. By default, a script is

    nsidered to be completed if it runs to conclusion and does not abort. Therefore, in many

    ses, it may not be necessary to call SetComplete from the script.

    t exists, the OnTransactionCommit event is processed.

    de:--------------------File1.asp-------------------TML>EAD>

    HEAD>ODY>

    orm action="File2.asp" method="POST">oductID:

    oduct Name:antity Wanted:put type="Submit" name="Submit" value="Submit">orm>

    BODY>

    HTML>

    --------------------File2.asp-------------------%Transaction = "Required"

    t connDB=server.createobject("adodb.connection")

    nnDB.Open "products", "", ""oductID = Response.Form("ProductID")ySQL="Select * from products Where productID = " & productID

    t rsProductSrch = Server.CreateObject("ADODB.Recordset")ProductSrch.Open mySQL, connDB, adOpenStatic, adLockPessimisticsProductSrch.BOF Or rsProductSrch.EOF ThenObjectContext.SetAbortseIf rsProductSrch.Fields("Quanity") < Response.Form("Order") Then

    Response.Write "There is not enough in stock to give the present order. There are " &ProductSrch.Fields("Quanity") & "."ObjectContext.SetAbortse

    rsProductSrch.Fields("Quanity") = rsProductSrch.Fields("Quanity") -Request.Form("Order")

    rsProductSrch.UpdateObjectContext.SetCompleted If

    ProductSrch.ClosennDB.Close>

    b OnTransactionAborted()sponse.Write "The transaction aborted because there was not enough quantity on hand to

  • 8/8/2019 DevGuru ASP Quickref

    59/85

    your order."d Sub

    b OnTransactionCommit()

    sponse.Write "The transaction was committed and your order is being sent."d Sub

    ere is enough to fill the order.tput:

    e transaction was committed and your order is being sent.

  • 8/8/2019 DevGuru ASP Quickref

    60/85

    VENT: ObjectContext.OnTransactionAbort

    e OnTransactionAbort event occurs when a transaction has been aborted for some kind of

    ocessing error. The OnTransactionAbort event is simply a subroutine with a reserved name

    at is referenced by the script. It can contain any script you may wish to run when an abort

    curs.

    de:

    %Transaction=Required Language="VBScript"sponse.Buffer = TRUE

    rver.ScriptTimeout = 5>TML>EAD>

    HEAD>ODY>

    %

    x=x+1Response.Write x & "
    "op While x < 10000>BODY>

    HTML>

    b OnTransactionAbort()sponse.Write "The transaction aborted because the script ran out of time. This is the

    ansaction Abort Handler."

    d Sub

    tput:e transaction aborted because the script ran out of time. This is the Transaction Abortndler.

  • 8/8/2019 DevGuru ASP Quickref

    61/85

    VENT: ObjectContext.OnTransactionCommit

    e OnTransactionCommit event occurs when a transaction has been completed. The

    nTransactionCommit event is simply a subroutine with a reserved name that is referenced

    the script. It can contain any script you may wish to run when the transaction is completed.

    de:% @Transaction=Required Language="VBScript" %>

    TML>EAD>

    HEAD>

    ODY>%

    x=x+1

    Response.Write x & "
    "op While x < 5>BODY>

    HTML>

    b OnTransactionCommit()sponse.Write "The transaction committed. This is the Transaction Commit Handler."d Sub

    tput:

    e transaction committed. This is the Transaction Commit Handler.

  • 8/8/2019 DevGuru ASP Quickref

    62/85

    VENT: Session_OnEnd

    e Session_OnEnd event occurs when the Session ends. Normally, a Session is ended by

    ng timed-out, either by default or by using Session.TimeOut, or by being abandoned by

    ng Session.Abandon. The Session_OnEnd event is simply a subroutine with a reserved

    me that is placed in the Global.asa file. The code in the event cannot affect the usercause he has quit the site.

    the example, there is no output because the user is already gone. The first line must specifye script language.

    te, only the Application, Server, and Session built-in objects are available from within theEnd event handler.

    de:---------------Global.asa--------------------------cript Language="VBScript" RUNAT=Server>

    b Application_OnEnd()d Sub

    b Application_OnStart()plication("NumSession") = 0plication("NumVisited") = 0d Sub

    b Session_OnEnd()

    plication("NumSession") = Application("NumSession") - 1d Sub

    b Session_OnStart()

    plication("NumSession") = Application("NumSession") + 1

    plication("NumVisited") = Application("NumVisited") + 1d Subscript>

    ---------------File1.asp----------------------------sponse.Write "You are " & Application("NumSession") & " of " & Application("NumVisited") &

    sers."

  • 8/8/2019 DevGuru ASP Quickref

    63/85

    VENT: Session_OnStart

    e Session_OnStart event occurs just before the server creates the Session object. The

    ssion_OnStart event is simply a subroutine with a reserved name that is placed in the

    obal.asa file. You can place any code you desire inside this subroutine. All of the built-in ASP

    ects are available from within the Session_OnStart event handler.

    de:---------------Global.asa--------------------------cript Language="VBScript" RUNAT=Server>

    b Application_OnEnd()d Sub

    b Application_OnStart()

    plication("NumSession") = 0plication("NumVisited") = 0d Sub

    b Session_OnEnd()

    plication("NumSession") = Application("NumSession") - 1d Sub

    b Session_OnStart()

    plication("NumSession") = Application("NumSession") + 1plication("NumVisited") = Application("NumVisited") + 1d Sub

    script>

    ---------------File1.asp----------------------------sponse.Write "You are " & Application("NumSession") & " of " & Application("NumVisited") &sers."

    tput:

    u are 1 of 3 users.

  • 8/8/2019 DevGuru ASP Quickref

    64/85

    ROPERTY: Response.Pics

    e Pics property adds the value of the PICS rating to the pics-label field in the the response

    ader for a document or a site. This statement must be located before the tag. TheCS label has quotes in the label, and the quotes must be replaced with, & chr(34) &. Or youn use double quotes.

    e PICS rating is as follows:

    lence = 2x = 1guage = 2

    dity = 0

    ing chr(34):

    de:% Response.Pics("(PICS-1.1 labels on " & chr(34)

    1997.01.05R08:15-0500" & chr(34) & " until " & chr(34) & "1999.12.31T23:59-0000" &r(34) & " ratings(v 2 s 1 l 2 n 0))")

    >

    ing double quotes:

    % Response.Pics("(PICS-1.1 labels on ""1997.01.05R08:15-0500"" until ""1999.12.31T23:59-

    00"" ratings(v 2 s1 l 2 n 0))")>

  • 8/8/2019 DevGuru ASP Quickref

    65/85

    OLLECTION PROPERTY: Request.QueryString

    quest.QueryString(Variable)[(Index)|.Count]

    e QueryString collection property contains, and allows you to retrieve, the values of the

    riables in the query string which are the statements that follows a question mark. Many

    ferent processes can produce a query string such as an anchor tag, a form submission, orping the string into the address box of the browser.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    riable

    e Variable specifies the name of the variable in the query string whose value is to be

    rieved.

    ere is one optional argument.

    dex

    e optional Index argument is used when the Variable argument has more than one value. It

    an integer, ranging from 1 to Request.QueryString(Variable).Count , which is used to

    ect values from the Variable. Count is the total number of multiple values.

    de:-------------------File1.asp----------------------TML>EAD>

    HEAD>ODY>

    HREF="File2.asp?language=ASP&type=general">Query sampleBODY>

    HTML>

    -------------------File2.asp----------------------%

    r Each item In Request.QueryString

    Response.Write(item & " = " & Request.QueryString(item) & VbCrLf)xt

    >

    tput:

    guage = ASPpe = general

  • 8/8/2019 DevGuru ASP Quickref

    66/85

    ETHOD: Response.Redirect

    sponse.Redirect(URL)

    e Redirect method stops processing the current script and attempts to connect the client to

    different URL. This is accomplished by adding an HTTP redirection header to the output

    eam that is being sent from the server to the client. Unfortunately, if page content haseady been sent to the client and if a proxy server lies between the server and the client, an

    or message can be generated. Therefore it is advisable to set Response.Buffer to true andcall Response.Clear just before calling Redirect.

    te in ASP 2.0, the buffering default setting is false and in ASP 3.0, the buffering defaulttting is true.

    ere is one mandatory argument.

    RL

    e URL argument is the Uniform Resource Locator (URL) that the browser is redirected to.

    de:----------File1.asp---------------

    % Response.Buffer = true %>

    TML>ODY>

    %sponse.Write "This is File1.asp and switching to File2.asp"sponse.Clear

    sponse.Redirect "File2.asp">BODY>HTML>

    ----------File2.asp-----------------TML>ODY>

    %

    sponse.Write "This is File2.asp">BODY>HTML>

    tput:e1 is written and then the browser will load File2:--------File1.asp------------------is is File1.asp and switching to File2.asp

    --------File2.asp-------------------

    is is File2.asp

  • 8/8/2019 DevGuru ASP Quickref

    67/85

    BJECT: Request

    e Request object provides access to all of the information that is passed in a request from

    e browser to the server. This information is stored among five types of Request collections.

    collection is similar to a data structure or array. Individual items in the collection are

    cessed via a unique key assigned to that item.

    variables can be accessed directly by calling Request(variable) without the collection

    me. In this case, the Web server searches the collections in the following order:ueryString, Form, Cookies, ClientCertificate, then ServerVariables.

    ROPERTY

    talBytes Property

    e TotalBytes property specifies the total number of bytes sent in the body of the HTTP

    quest.

    OLLECTION PROPERTIES

    entCertificate Collection Property

    e ClientCertificate collection property contains the values of the client certification fields ofe request.

    ookies Collection Property

    e Cookies collection property contains the values of the cookies sent in the request.

    rm Collection Property

    e Form collection property contains the values of the elements posted to a form

    ng the POST method.

    ueryString Collection Property

    e QueryString collection property contains the values of the variables in the HTTP queryng, which are the statements that follow a question mark.

    rverVariables Collection Property

    e ServerVariables collection property contains the values of server environmental variables.

    is allows access to the HTTP headers.

    ETHOD

    naryRead (Count) Method

    e BinaryRead method retrieves the data that was sent to the server from the browser as

    rt of a POST request, and returns the number of bytes read.

  • 8/8/2019 DevGuru ASP Quickref

    68/85

    ROPERTY: Request.TotalBytes

    quest.TotalBytes

    e TotalBytes property is a read-only value that specifies the total number of bytes sent by

    e client to the server in the body of the HTTP request.

    e value returned by TotalBytes can be used as the argument of

    quest.BinaryRead(Count) .

    de:---------------File1.html-----------------

    TML>EAD>

    HEAD>ODY>ORM ACTION="File2.asp" METHOD="POST">

    me:
    e:
    x:

    NPUT TYPE="Submit" NAME="submit" VALUE="submit">
    FORM>BODY>HTML>

    ---------------File2.asp------------------

    %m ByteCountteCount = Request.TotalBytessponse.Write("ByteCount = " & ByteCount & " bytes")

    >

    tputs dependent on the data entered into the form.r example, if Name=Bill, Age=56, and Sex=male.

    teCount = 39 bytes

  • 8/8/2019 DevGuru ASP Quickref

    69/85

    OLLECTION PROPERTY: Request.ServerVariables

    quest.ServerVariables(EnvironmentVariable)

    e ServerVariables collection property contains, and allows you to retrieve, the values of

    rver environment variables.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    vironmentVariable

    e EnvironmentVariable argument can be any one of the following forty three variables:

    ALL_HTTP are all HTTP headers sent by the client.

    ALL_RAW retrieves all headers in the raw-form.

    APPL_MD_PATH retrieves the metabase path.

    APPL_PHYSICAL_PATH retrieves the physical path corresponding to the

    metabase path.

    AUTH_PASSWORD is the value entered in the client's authentication dialog.

    AUTH_TYPE is the authentication method that the server uses to validate

    users.

    AUTH_USER is the raw authenticated user name.

    CERT_COOKIE is an unique ID for client certificate which is returned as a

    string.

    CERT_FLAGS is where bit0 is set to 1 if the client certificate is present, and

    bit1 is set to 1 if the certifying authority of the client certificate is invalid.

    CERT_ISSUER is the issuer field of the client certificate.

    CERT_KEYSIZE is the number of bits in Secure Sockets Layer connection key

    size.

    CERT_SECRETKEYSIZE is the number of bits in the server certificate private

    key.

    CERT_SERIALNUMBER is the serial number field of the client certificate.

    CERT_SERVER_ISSUER is the issuer field of the server certificate.

    CERT_SERVER_SUBJECT is the subject field of the server certificate.

    CERT_SUBJECT is the subject field of the client certificate.

    CONTENT_LENGTH is the length of the content header as sent by the client.

    CONTENT_TYPE is the data type of the content.

  • 8/8/2019 DevGuru ASP Quickref

    70/85

    GATEWAY_INTERFACE is the revision of the CGI specification used by the

    server.

    HTTP_ is the value stored in the header HeaderName.

    HTTP_ACCEPT returns the value of the Accept header.

    HTTP_ACCEPT_ENCODING returns the value of the Accept encoding.

    HTTP_ACCEPT_LANGUAGE returns a string that specifies the language to be

    used for displaying content.

    HTTP_CONNECTION returns a string containing information about the

    connection.

    HTTP_COOKIE returns the cookie string that was included with the request.

    HTTP_HOST returns a string containing information about the host.

    HTTP_REFERER returns a string containing the original URL when a redirect

    has occurred.

    HTTP_USER_AGENT returns a string describing the browser used to send therequest.

    HTTP_UA_PIXELS returns a string detailing the screen resolution of the user

    agent.

    HTTP_UA_COLOR returns a string with color information.

    HTTP_UA_OS returns a string stating the operating system of the user agent.

    HTTP_UA_CPU returns a string stating the processor type used by the user

    agent.

    HTTPS returns ON if the request came in through secure channel or OFF if the

    request is through a non-secure channel.

    HTTPS_KEYSIZE is the number of bits in Secure Sockets Layer (SSL)

    connection key size.

    HTTPS_SECRETKEYSIZE is the number of bits in server certificate private

    key.

    HTTPS_SERVER_ISSUER is the issuer field of the server certificate.

    HTTPS_SERVER_SUBJECT is the subject field of the server certificate.

    INSTANCE_ID is the ID for the Internet Information Server (IIS) instance in text

    format.

    INSTANCE_META_PATH is the metabase path for the instance of Internet

    Information Server (IIS) that responds to the request.

    LOCAL_ADDR returns the server address on which the request came in.

    LOGON_USER is the Windows account that the user is logged into.

    PATH_INFO is extra path information as given by the client.

  • 8/8/2019 DevGuru ASP Quickref

    71/85

  • 8/8/2019 DevGuru ASP Quickref

    72/85

    BJECT: Response

    odified in version 3.0

    e Response object sends information back to the user (browser).

    ROPERTIES

    ffer Property Modified in version 3.0e Buffer property tells whether the page output being sent to the browser is buffered.

    cheControl Property

    e CacheControl property determines whether a proxy server can cache the Active Server

    ge.

    arset Property

    e Charset property appends the name of the character set being used to the content-type

    ader contained in the response object.

    ontentType Property

    e ContentType property specifies the HTTP content type/subtype for the response header.

    pires Property

    e Expires property specifies the length of time in minutes until a cached page on the

    owser expires.

    piresAbsolute Property

    e ExpiresAbsolute property specifies a date and time when a cached page on the browser

    l expire.

    ClientConnected Property Modified in version 3.0

    e IsClientConnected property indicates whether the browser has disconnected from therver since the last Response.Write.

    CS Property

    e PICS property specifies the value of a PICS rating label for a document or a site.

    atus Property

    e Status property specifies the value of the status line returned by the server.

    OLLECTION PROPERTIES

    ookies Collection Property

    e Cookies collection property allows you to add a cookie to a browser and add values to theokie.

    ETHODS

    dHeader Name, Value Method

    e AddHeader method adds a new named HTTP header with a specific value to the

    sponse.

    ppendToLog (String) Method

    e AppendToLog method adds a string to the end of an entry in the Web server log for this

  • 8/8/2019 DevGuru ASP Quickref

    73/85

    quest.

    naryWrite (Data) Method

    e BinaryWrite method sends specific data to the current HTTP output without any character

    nversions.

    ear Method

    e Clear method clears (erases) any buffered HTML output.

    d Method

    e End method causes the web server to stop processing the script and to return the current

    sults without processing the rest of the file.

    ush Method

    e Flush method sends the contents of the buffer.

    direct (URL) Method

    e Redirect method tries to connect the browser to a different URL.

    rite (variant) Method

    e Write method sends any specified variant to the browser.

  • 8/8/2019 DevGuru ASP Quickref

    74/85

    ROPERTY: Response.Status

    e Status property specifies the value of the HTTP status line returned by the server This is a

    ee digit number followed by a short description.

    de:%

    Address = Request.ServerVariables("REMOTE_ADDR")

    PAddress "208.5.64.223" ThenResponse.Status = "403 Access Forbidden"Response.Write Response.Status

    Response.Endd If

    >

    TML>

    EAD>HEAD>ODY>

    u have accessed this page through the IP Address of 208.5.64.223. HTML>

    e output of the above is the following if the IP address of the client is 208.5.64.223:u have accessed this page through the IP Address of 208.5.64.223.

    herwise the output is as follows if the IP address is not 208.5.64.223:

    3 Access Forbidden

  • 8/8/2019 DevGuru ASP Quickref

    75/85

    ETHOD: Response.Write

    sponse.Write(Variant)

    e Write method writes any specified string to the HTTP output.

    ere is one mandatory argument.

    riant

    e Variant argument is the data to be written as a string. A variant is a VBScript data type

    d includes characters, integers, and strings. The variant cannot contain the charactermbination of %>.

    de:%

    sponse.Write "Hello World"sponse.Write "
    "

    >

    tput:llo World

  • 8/8/2019 DevGuru ASP Quickref

    76/85

    ROPERTY: Server.ScriptTimeout

    e ScriptTimeout property specifies the amount of runtime in seconds for a script before it

    minates. The default value is 90 seconds.

    e following code causes a script to timeout if the script takes more than 150 seconds tomplete.

    % Server.ScriptTimeout = 150 %>

    e value of the ScriptTimeout property can be retrieved as well.

    % timeout = Server.ScriptTimeout %>

  • 8/8/2019 DevGuru ASP Quickref

    77/85

    BJECT: Server

    odified in version 3.0

    e Server object provides access to the utility functions of the server.

    ROPERTY

    riptTimeout Propertye ScriptTimeout property is the amount of runtime in seconds for a script before it

    minates.

    ETHODS

    eateObject (ObjectID) Method

    e CreateObject method creates an instance of an object to use in an Active Server Page.

    ecute (Path) Method Implemented in version 3.0

    e Execute method allows you to call another ASP page from inside an ASP page. When the

    led ASP page completes its tasks, you are then returned to the calling ASP page.

    etLastError Method Implemented in version 3.0

    e GetLastError method returns an ASPError object that describes any pre-processing,

    ntime, or script compiling errors that occurred.

    TMLEncode (String) Method

    e HTMLEncode method applies HTML syntax to a specified string of ASCII characters.

    apPath (Path) Method

    e MapPath method maps a relative or virtual path to a physical path.

    ansfer (Path) Method Implemented in version 3.0e Transfer method allows you to transfer all of the state information for all of the built-in

    ects from one ASP page to another. Unlike the Execute method, when the ASP page that

    u have transferred to is finished, you do not return the original ASP page.

    RLEncode (String) Method

    e URLEncode method applies URL rules to a specified string of ASCII characters.

  • 8/8/2019 DevGuru ASP Quickref

    78/85

    ETHOD: Server.Transfer

    plemented in version 3.0

    rver.Transfer(Path)

    e Transfer method allows you to transfer from inside one ASP page to another ASP page.

    of the state information that has been created for the first (calling) ASP page will be

    nsferred to the second (called) ASP page. This transfered information includes all objectsd variables that have been given a value in an Application or Session scope, and all items

    the Request collections. For example, the second ASP page will have the same SessionID

    the first ASP page.

    hen the second (called) ASP page completes its tasks, you do not return to the first (calling)P page.

    contrast, the Execute method allows you to call another ASP page, and when the called

    ge has completed its tasks, you return to the calling ASP page.

    ere is one mandatory argument.

    th

    e Path argument is a string specifying either the absolute or relative path of the ASP page

    ng called. The file name must be included in the path. The entire Path must be enclosed

    ide a pair of quotes.

    this example, the first ASP page (CallingAsp.asp) has no output.

    de:

    ------CallingAsp.asp----------%

    plication("name") = "Application Maker"plication("publishdate") = "05/15/01"plication("author") = "DevGuru"

    t Application("Obj1") = Server.CreateObject("ADODB.Connection")

    rver.Transfer("CalledAsp.asp")>

    ------CalledAsp.asp----------

    %;sponse.Write "Output from CalledAsp.asp"r Each Item in Application.Contents

    If IsObject( Application.Contents(Item)) ThenResponse.Write Item & " is an object.
    "

    ElseResponse.Write Item & "=" & Application.Contents(Item) & "
    "

    End Ifxt

    >

    tput:tput from CalledAsp.aspme=Application Maker

  • 8/8/2019 DevGuru ASP Quickref

    79/85

    blishdate=05/15/01thor=DevGuru

    BJ1 is an object.

  • 8/8/2019 DevGuru ASP Quickref

    80/85

    ETHOD: Server.URLEncode

    rver.URLEncode(String)

    e URLEncode method takes a string and converts it into a URL-encoded format. For

    ample, you can use URLEncode to ensure that hyperlinks in your Active Server Pages are

    the correct format.

    ere is one mandatory argument.

    ring

    e String argument is the string to be encoded.

    de:% Response.Write Server.URLEncode("http://www.issi.net") %>

    tput:p%3A%2F%2Fwww%2Eissi%2Enet

  • 8/8/2019 DevGuru ASP Quickref

    81/85

    BJECT: Session

    odified in version 3.0

    e first time a user makes a document request, a Session object is assigned to the user and

    s used to store, share, and retrieve information concerning the user session. By default, the

    ssion object is destroyed after a session has been idle for twenty minutes.

    ROPERTIES

    odePage Property

    e CodePage property specifies the server codepage that will be used to display dynamic

    ntent.

    CID Property

    e LCID property specifies the location identifier that will be used to display dynamic content.

    ssionID Property

    e SessionID property returns the unique identifier for a user session.

    meout Property

    e Timeout property is the length of time in minutes before an idle session is terminated.

    OLLECTION PROPERTIES

    ontents Collection Property

    e Contents collection property contains all of the items that have been created and added to

    e Session object through script commands, rather than using the HTML tag.

    aticObjects Collection Property

    e StaticObjects collection property contains all of the items created in the Global.asa file

    ng the HTML tag within the scope of the Session object.

    ETHODS

    bandon Method

    e Abandon method terminates a user session, destroys all data and objects in the current

    ssion object, and releases its resources.

    ontents.Remove Method Implemented in version 3.0

    e Contents.Remove method is used to remove a single item from a Contents collection.

    ontents.RemoveAll Method Implemented in version 3.0

    e Contents.RemoveAll method is used to remove all items from a Contents collection.

    VENTS

    nEnd Event

    e OnEnd event occurs when the Session quits. The signal of this event will run a handler

    ript in the Global.asa file, if the script exists.

    nStart Event

    e OnStart event occurs before the start of any new Session by a user. The signal of this

    ent will run a handler script in the Global.asa file, if the script exists.

  • 8/8/2019 DevGuru ASP Quickref

    82/85

  • 8/8/2019 DevGuru ASP Quickref

    83/85

    ROPERTY: Session.SessionID

    e SessionID property returns the unique session identifier for the current user. The identifier

    generated by the server and is a Long data type.

    de:

    % Response.Write "Your Session ID is " & Session.SessionID %>

    tput:

    ur Session ID is 465107831

  • 8/8/2019 DevGuru ASP Quickref

    84/85

    ROPERTY: Session.Timeout

    e Timeout property specifies the number of minutes that can elapse while a session is idle

    fore it is terminated. The default is 20 minutes. If the user does not refresh the page orquest another page within the allotted time, the session is automatically terminated and thesources are released.

    e following code causes the session to terminate if the session is idle for more than 35

    nutes.

    % Session.Timeout = 35 %>

  • 8/8/2019 DevGuru ASP Quickref

    85/85

    OLLECTION PROPERTY: Session.StaticObjects

    ssion.StaticObjects(Key)

    e StaticObjects collection property contains a list of all of the items that have been created

    d added to the Session object using the HTML tag.

    u can iterate through a collection using a For Each item in ... Next loop.

    ere is one mandatory argument.

    y

    e Key argument is the name of the item to retrieve.

    de:------Global.asa-------------

    OBJECT RUNAT=Server SCOPE=Session ID=MyInfo PROGID="MSWC.MyInfo">OBJECT>

    OBJECT RUNAT=Server SCOPE=Session ID=MyConnectionROGID="ADODB.Connection">OBJECT>

    OBJECT RUNAT=Server SCOPE=Session ID=MyADRot PROGID="MSWC.ADRotator">OBJECT>

    -------File.asp-----------------

    %r Each Item In Session.StaticObjectssponse.Write Item & "
    "xt

    >

    tput:yInfoyConnection

    yADRot