DS 420ssg b | ![]() ![]() |
Dr.Elliott |
5. ASP and COM
Active Server Pages (ASP) is a server-side scripting environment that you can use to create and run dynamic, interactive Web-server applications. ASP allows you to combine HTML, scripting, components, and transactions to create interactive Web content or Web-based applications. ASP is a feature of Internet Information Server (IIS) version 3.0 and later.
To create dynamic Web pages, you need server-side processing capabilities. Initially, developers used CGI for this. It is simple, and could run on lots of platforms
Internet Server Application Programming Interface (ISAPI) applications are compiled as DLLs that are loaded by the World Wide Web service at startup. Compared to scripts written for CGI, ISAPI applications perform much better and requires less overheads. Since ISAPI DLLs runs in-process with IIS, each user request dose not spawn a separate process.
However, both CGI and ISAPI have disadvantages. programs that run in a CGI environments use and address space separate from the Web server, slowing things down considerabluy. ISAPI DLLs need to be written in C/C++
With ASP, HTML content creation and sever side code development become the same process, enabling you to focus directly on the look and your Web pages, weaving dynamic elements into your pages as appropriate.
ASP are ASCII files that contain text, HTML, and script directives. The following example code is a complete, simple ASP:
<HTML>
<BODY>
<H3>Welcome to Exploration Air.</H3>
The time here is <%=
Time()%><BR>
The date is <%=Date()%>.
</BODY>
</HTML>
Script consists of commands inside HTML <SCRIPT> tags, or the inline equivalent <%> tags that can be processed on the server by the server engine. When a user requests a URL with an .asp file extension, the ActiveX server engine reads through the file from top to bottom, executing any commands and sending text and HTML back to the user¡¦s browser. ActiveX Server scripting is completely integrated with HTML pages.
In the example above, server-side scripts are designated with an opening and closing <%> tag and are processed before the page is sent to the browser. In this case, the sample displays the current time and date. All server scripting is processed on the server, and only HTML is sent to the client.
Because script in ASP pages runs on the server, it has access to a number of objects available on the server. The following table describes these objects:
Object Description
Request Retrieves the values that the browser passes to the server during an HTTP request.
Response Controls what information is sent to a browser in the HTTP response message.
Session Used to manage and store information about a particular user session.
Application Used to manage and store information about the Web application.
Server Provides access to resources that reside on a server.
With ASP, you can:
Retrieve information passed from the browser to the server using the Request object.
Send output to the browser using the Response object.
Store information for a specific user using the Session object.
Share information among all users of your application using the Application object.
Work with the properties and methods of components on the server using the Server object.
Applications written using ASP can take advantage of the benefits of COM components. ASP files can create COM objects and execute methods of those objects in response to a user request.
ASP Add-on Components
In addition to the five intrinsic objects already discussed, ASP ships whith five add-on components. They are provided as add-on DLLs. The component provided are:
Ad Rotator, Browser Capabilites, Database Access, Conteant Linking, and File Access. These components enable you to ceate dynamic interavtive Web pages using these prebuilt server components .
Customized ActiveX Server Component
In the same time, you can build a custom ActiveX Sever component, and use it for your ASP.
Calling COM Components from ASP
There are a few different methods of creating COM objects from an ASP. The simplest is to use the CreateObject method of the Server object to create an instance of an object.
The following example code calls the FrequentFlyer component using its PROGID and invokes a method. The following example code is from SubmitTicket.asp in the Exploration Air sample application:
FFComponent = Application("FrequentFlyerComponent") + ".FrequentFlyer"
set oFrequentFlyer = Server.CreateObject(FFComponent)
'this prevents an error if the FrequentFlyer component is not installed
if NOT oFrequentFlyer is Nothing then
' Add origin points
oFrequentFlyer.Create clng(Session("CustomerID")), _
clng(OriginReservationID) , _
"Ticket", _
cstr(Session("OriginSeat")), _
clng(Session("OriginMiles"))
¡@