Compartilhar via


OBJECT Declarations

You can create objects with session or application scope in the Global.asa file by using the extended <OBJECT> tag. This tag is self-contained and can be used outside of any <SCRIPT> tags.

The objects declared in the Global.asa file are not created until the server processes a script that calls that object. This saves resources by creating only the objects that are needed.

The server does not call the OnStartPage and OnEndPage methods for objects created with application scope. For more information about component scope, see Setting Object Scope and Determining Component Scope.

Syntax

<OBJECT RUNAT=Server SCOPE= Scope ID= Identifier{ PROGID="progID"| CLASSID="ClassID"} >

. . .

</OBJECT>

Parameters

  • Scope
    Specifies the scope of the object. In the Global.asa file, Scope is set to either Session or Application.

  • Identifier
    Specifies a name for the object instance.

  • ProgID
    An identifier associated with a class identifier. Either ProgID or ClassID must be specified in the <OBJECT> tag. The format for ProgID is [Vendor .]Component[ .Version].

  • ClassID
    Specifies a unique identifier for a COM class object. Either ProgID or ClassID must be specified in the <OBJECT> tag.

Remarks

The objects declared in the Global.asa file can be used by any script in the application. For example, if you declared the following object:

--- Global.asa --- 
<OBJECT RUNAT=Server SCOPE=Session ID=MyAd PROGID="MSWC.AdRotator"> 
</OBJECT> 

You could reference the object MyAd from any page in the application:

--- Some.asp --- 
<%= MyAd.GetAdvertisement("/ads/adrot.txt") %>   

Example Code

The first of the following examples creates an object of session scope named MyConnection by using the ProgID parameter. The second example uses the ClassID parameter.

<OBJECT RUNAT=Server SCOPE=Session ID=MyConnection PROGID="ADODB.Connection"> 
REM Object Script 
</OBJECT> 

<OBJECT RUNAT=Server SCOPE=Session ID=MyConnection CLASSID="Clsid:8AD3067A-B3FC-11CF-A560-00A0C9081C21"> 
REM Object Script 
</OBJECT> 

Requirements

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

See Also

Other Resources

ASP.NET Server-Side Object Tag Syntax