Using a Windows® Script Component, you can include the functionality of Active Server Pages (ASP). Doing so allows you to isolate server script into a component that can be easily called from ASP pages and which makes it easy to reuse ASP code. For example, you might have several ASP pages that process forms. Rather than implement all the form-processing logic directly in each ASP page, the ASP pages could all call a script component with form-handling logic that you create.
To create an ASP script component, create a script component normally, as described in Script Component File Contents. Use the <implements> element to implement the ASP interface handler, setting the type attribute of the <implements> element to "ASP." Doing so provides the means for accessing ASP objects: Response, Request, Server, Session, and Application. In an ASP script component, you can use these objects as you would directly in an ASP page. The ASP interface handler is built into the script component run-time (Scrobj.dll), so no external interface handler is required.
When the script component runs, it uses the same namespace as the ASP page that called it. The script component can access the Request and Server objects as if it were in the ASP page that called it. The script component also has access to the same Session and Application variables that the calling ASP page does. Similarly, if the ASP script component calls a method on the Response object, the result of these calls is available in the calling page. For example, if you call Response.Write, the output is directed to the calling ASP page.
The following shows a simple ASP script component that exposes a property and a method. The applicationVar1 property makes available the hypothetical Application variable called Var1. The AddDate method outputs the current date into the calling ASP page.
Note A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<component id="ASPScriptlet"> <registration progid="ASPScriptlet"/> <public> <property name="applicationVar1"/> <method name="AddDate"/> </public> <implements type="ASP"/> <script language="VBScript"> <![CDATA[ dim applicationVar1 applicationVar1 = Application("Var1") Sub AddDate() Response.Write(Date) End Sub ]]> </script> </component>
The calling ASP page might look like this:
<HTML> <HEAD> <TITLE>Testing the Script Components ASP Handler</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <H1>Testing the ASP Handler</H1>
<%Set wscASP = CreateObject("ASPScriptlet")%><P>The current date is <%= wscASP.AddDate()%></P> <P>The value of the Application(Var1) variable is <%= wscASP.applicationVar1%></P> </BODY> </HTML>