<% If Request("DontFrame")<>1 Then Response.Redirect "/iissamples/sdk/asp/docs/SampFram.asp?ovfile=/iishelp/iis/htm/sdk/samp2v77.asp&srcfile=Simple/Components" %> Using Components

Using Components

The server components included when you install IIS provide functionality to ASP scripts in powerful, easy-to-use packages. You could spend a lot of time and resources creating and implementing this functionality with ASP scripting alone.

You can access a component's functionality from within an ASP script in the same way, no matter which component you require. First, create an instance of the object using the appropriate and unique program ID of the component you want to instantiate. Once the instance is created, you can use references to the object to access any of the properties or methods provided by that component.

This example uses the Tools object of the Tools component, which you can use to accomplish a number of miscellaneous tasks, including form processing and file ownership management. The random number generation capabilities of the Tools object are demonstrated here.

The Server.CreateObject method is used to create an instance of the Tools object, using the program ID MSWC.Tools, and the variable example is set as an object reference to the new component instance. You access the desired method, Random in this case, by using the standard object.method format. Thus, each time this script is run, example.Random returns a random number between -32767 and 32767. This number is then sent to the client browser.

Note This component is not installed with IIS. You can install it from the CD included with the IIS Resource Kit. The ProgID declared by the component version installed from this source specifies "IISSamples" in the vendor component of the ProgID, not "MSWC." Therefore, the Server.CreateObject invocation in this sample script must be modified to reflect the proper component ProgID.


© 1997 by Microsoft Corporation. All rights reserved.