Compartilhar via


Server.CreateObject Method

The CreateObject method creates an instance of a server component. If the component has implemented the OnStartPage and OnEndPage methods, the OnStartPage method is called at this time.

CreateObject(
      progID
)

Parameters

  • progID
    Specifies the type of object to create. The format for progID is [Vendor.] Component[ .Version].

Return Values

This method has no return values.

Example Code

The following example creates a server component, MyAd, as a MSWC.AdRotator component that can be used to automate the rotation of advertisements on a Web page.

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

For more information about server components, see Setting the Scope of COM Objects in ASP Pages and Creating COM Components for ASP.

Applies To

Server Object

Remarks

By default, objects created by the Server.CreateObject method have page scope. This means that they are automatically destroyed by the server when it finishes processing the current ASP page.

To create an object that has session or application scope, you can either use the <OBJECT> tag in the Global.asa file and set the SCOPE attribute to SESSION or APPLICATION, or you can store the object in a session or application variable.

For example, an object stored in a session variable, as shown in the following script, is destroyed when the Session Object object is destroyed. That is, when the session times out, or the Session.Abandon method is called.

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

You can also destroy the object by setting the variable to

Nothing

or by setting the variable to a new value, as shown in the following code. The first example releases the object ad. The second replaces ad with a string.

<% Session("ad") = Nothing %> 
<% Session("ad") = "some other value" %> 

You cannot create an object instance with the same name as a built-in object. For example, the following returns an error.

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

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