Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

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

Application_OnStart / Application_OnEnd

Application Object

One of the key functions of Application Object is the application control on the server.

Application_OnStart Event

Application_OnStart Event occurs on the start of the Application before the first Session_OnStart event. Available objects are Application Object and Server Object built-in objects.

Syntax:

<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Application_OnStart
    ...Script...
End Sub
</SCRIPT>

 Or in Global.asa. Imply

<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Application_OnStart
    ...Scripts...
End Sub
</SCRIPT>

Parameters:

ScriptLanguage

The parameter "ScriptLanguage" is used to specify the scripting language used in writing the event script.

Script

The parameter "Script" is the program written by the scripting language for the script interpreter of the Web Server.

Remarks:

The scipting language can be any supported language, such as VBScript or JScript. When more than one event using the same scripting language, all event sub-rountine can be combined under a single set of <SCRIPT> tags.

 In the Application_OnStart script, only the Application Object and Server Object built-in objects are available. Referencing the Session Object, Request Object, or Response Object objects in the Application_OnStart event script will cause an error.

Since the Application_OnStart script can be called only once by the first session when the application start, Application.Lock and Application.Unlock methods are not needed, .

Examples:

  • Use Application_OnStart to specify application start

    ASP script command:

    <SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
    Sub Application_OnStart
        Application("AppStart") = 1
    End Sub
    </SCRIPT>

Application_OnEnd Event

Application_OnEnd Event occurs on the end of the Application after all the Session_OnEnd event. Available objects are Application Object and Server Object built-in objects.

Syntax:

<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Application_OnEnd
    ...Script...
End Sub
</SCRIPT>

 Or in Global.asa. Imply

<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Application_OnEnd
    ...Scripts...
End Sub
</SCRIPT>

Parameters:

ScriptLanguage

The parameter "ScriptLanguage" is used to specify the scripting language used in writing the event script.

Script

The parameter "Script" is the program written by the scripting language for the script interpreter of the Web Server.

Remarks:

The scipting language can be any supported language, such as VBScript or JScript. When more than one event using the same scripting language, all event sub-rountine can be combined under a single set of <SCRIPT> tags.

In the Application_OnEnd script, only the Application Object and Server Object of built-in objects are available, however the Server.MapPath method is not available.

And by default, Application_OnEnd runs as the Anonymous User, as defined for the application. If there isn't an Anonymous user, or the Logon for the Anonymous user fails, the OnEnd function will not be called, and an event will be logged.

Examples:

  • Use Application_OnEnd to specify application end

    ASP script command:

    <SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
    Sub Application_OnStart
        Application("AppStart") = 1
    End Sub
    Sub Application_OnEnd
        Application("AppStart") = 0
    End Sub
    </SCRIPT>

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

Contents / StaticObjects

Application Object

One of the key functions of Application Object is the application data control on the server.

Application.Contents Collection

Application.Content Collection adds or sets the value of an item of the Contents collection of Application object through script commands.

Syntax:

Application.Contents( Key)

 Or in an ASP file.  Imply

<% Application.Contents( Key) %>

Parameters:

Key

The parameter "Key" is used to specify the name of the item to retrieve.

Remarks:

The Contents collection contains only the list of items that have been declared in application scope using script commands not the <OBJECT> tags. Therefore both an application declaration and objects created by using the Server.CreateObject are contained in the Contents Collection

The Contents collection can be used to obtain the list of items or a particular item that have been declared in application scope.

But the items in the Contents collection can only be removed from the collection by using the Remove and RemoveAll methods.

The Contents Collection is in the form of collection, the values of the keys of the cotents collection should be retrieved using a for each element loop in order to get the name of the element. Or using a for index loop is the key is predetermined..

Examples:

  • Use Application.Contents to retrieve the value of item

    ASP script command:

    <%
    Application("App1") = "App1value"
    Application("App2") = "App2value"
    Application("App3") = "App3value"
    For Each element in Application.Contents
    Response.write element & " = " & Application(element) & "<br>"
    Next
    For itemno = 1 to Application.Contents.Count
    Response.Write CStr(itemno) & " = " & _
    Application.Contents(itemno) &  "<br>"
    Next
    %>

    HTTP response output:

    App1 = App1value<br>
    App2 = App2value<br>
    App3 = App3value<br>
    1 = App1value<br>
    2 = App2value<br>
    3 = App3value<br>

    HTML web page ouput:

    App1 = App1value
    App2 = App2value
    App3 = App3value
    1 = App1value
    2 = App2value
    3 = App3value

Application.StaticObjects Collection

Application.StaticObjects Collection collects all objects added to the session through the <OBJECT> tag within the Application scope

Syntax:

Application.StaticObjects( Key)

 Or in an ASP file. Imply

<% Application.StaticObjects( Key) %>

Parameters:

Key

The parameter "Key" is used to specify the name of the item to retrieve.

Remarks:

The StaticObjects collection contains only the list of items that have been declared in application scope using <OBJECT> tags not the script commands. Therefore both an application declaration and objects created by using the Server.CreateObject are contained in the Contents Collection not in StaticObject collection.

The StaticObjects collection can be used to obtain the list of items or a particular item that have been declared in application scope.

The StaticObjects Collection is in the form of collection, the values of the keys of the StaticObjects  collection should be retrieved using a for each element loop in order to get the name of the element.

Examples:

  • Use Application.StaticObjects to retrieve the value of item

    ASP script command:

    ------Global.asa-----------
    <object id="ExAdRot" runat="server"
    progid="MSWC.AdRotator" scope="application">
    </object>

    <%
    For Each element in Application.StaticObjects
    Response.write element & "<br>"
    Next
    %>

    HTTP response output:

    ExAdRot<br>

    HTML web page ouput:

    ExAdRot

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

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

Previous Month  JUL  2014  Next Month
SMTWTFS
12345
6789101112
13141516171819
20212223242526
2728293031

Sideway BICK Blog

11/02


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