1 / 35

ASP Components

10. ASP Components. Internet Programming Using VBScript and JavaScript. 10. Objectives. In this chapter you will: Learn how the Component Object Model is used within a Web application Use the server object to integrate your ASP page with ASP components

trish
Download Presentation

ASP Components

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10 ASP Components Internet Programming Using VBScript and JavaScript

  2. 10 Objectives • In this chapter you will: • Learn how the Component Object Model is used within a Web application • Use the server object to integrate your ASP page with ASP components • Detect support for specific browser features using the Browser Capabilities component

  3. 10 Objectives • In this chapter you will: • Create a Web page that rotates banner ads using the AdRotator component • Send e-mail via an ASP page using the CDONTS object • Locate other third-party ASP components on the Internet

  4. 10 ASP Components • A component is a piece of software code that defines objects, properties, and methods, and encapsulates the entire code within itself • Components that conform to the Component Object Model (COM) are known as COM objects • The Component Object Model is a standard that allows independent components to communicate with each other • COM objects can be installed on a client’s computer or on the server

  5. 10 ASP Components • Server-side COM objects are often referred to as server components, active server components, or ASP components • ASP components are simply COM objects installed on the server that are used within Web applications • Microsoft provides several additional ASP components, including the Browser Capabilities component, the AdRotator component, the Database Access component, and the CDONTS component

  6. 10 ASP Components • Third-party software such as the Microsoft SMTP Server contains ASP components that can be used to interface with their software • The SMTP Server uses the CDONTS component to interface with the SMTP Server • You can use CDONTS to send e-mail from an ASP page

  7. 10 How ASP Applications Communicate with Server Components

  8. 10 Integrating ASP Components into ASP Pages • Because ASP components are COM components, they can contain predefined objects, properties, and methods • After the ASP components are installed, your Web pages can access their objects, properties, and methods • The ASP built-in server object contains a method called createobject that allows you to create an instance of an object from any ASP page

  9. 10 Assigning Properties and Calling Methods • Once you have created the instance of the object using the component, you can access its properties and methods by referring to the name of the variable and the name of the property or method • The syntax below illustrates how to retrieve the property value of an object, store it in a variable, and write it to the Web page <%varProperty = objName.PropertyName %> <% = varProperty %>

  10. 10 Assigning Properties and Calling Methods • To modify the value of the property, you must identify the name of the object, the property name, and the new value • When you call the method of an object, you can pass arguments (also called parameters) to the method • When you assign an object to a variable, you are assigning a memory location to the object

  11. 10 The Browser Capabilities Component • The Browser Capabilities component refers to an external text file on the server known as the Browser Capabilities Detection File, which contains information about most of the browser software programs • The Browser Capabilities Detection File lists each browser with its version number and a list of features it supports • While Browscap.ini contains many of the features supported by browsers, it does not contain all of them

  12. 10 The Browser Capabilities Component • There are other third party components such as BrowserHawk from cyScape that can detect more features for a wider selection of browsers • To detect the browser features using the Browser Capabilities component’ refer to the procedures outlined on pages 369 and 370 of the textbook

  13. 10 The AdRotator Component • You can use the AdRotator component to create and maintain banner advertisements on ASP pages • The AdRotator component, called Adrot.dll, contains a method that you can use not only to display the ad, but also to manage the frequency with which the banner ad is displayed • The information used to manage the ad is located in a single text file called the Rotator Schedule File, which means that you can change the ad across several Web pages simply by editing this one file • When users click the ad, they are redirected to a new Web page by a Redirection File

  14. 10 Creating the Rotator Schedule File • The Rotator Schedule File, which you create using a text editor such as Notepad, is a text file that contains information about the ads to be displayed on an ASP page • It is divided into two sections • The first section defines the general parameters for all ads • The second section contains the parameters for specific ads • A single line with an asterisk (*) divides the two sections

  15. 10 Creating the Rotator Schedule File • The top line of the first section contains a statement that redirects the user to an ASP page that contains a redirection script • The second section of the Rotator Schedule File identifies four specific parameters for each ad as it rotates into the Web page • The third parameter provides a text description of the ad for browsers without graphics capabilities

  16. 10 Creating the Redirection File • The Redirection File is an ASP page that can be created in Notepad • The name of the Redirection File must match the page identified in the first line of the Rotator Schedule File • The Redirection File retrieves the URL for the link from the QueryString • The the Redirection File uses server-side redirection to redirect users to the specified URL

  17. 10 Creating the ASP Page to Display the Banner Ads • An instance of the AdRotator component is created using the createobject method of the server object • The name of the AdRotator component is “MSWC.AdRotator” • Within the ASP page, the write method is used to write out the information returned from the GetAdvertisement method • The GetAdvertisement method of the AdRotator component writes out the anchor and image tags for the banner ad

  18. 10 Creating the ASP Page to Display the Banner Ads • The other properties of the AdRotator component include border, which allows you to override the border settings in the Rotator Schedule File; clickable, which allows you to specify whether you want the image to contain active hyperlinks, and is set to true by default; and TargetFrame, which indicates into which frame the image is loaded

  19. 10 Banner Ad Graphics • You can create your own banner ads, using a graphics program • There are many commercial graphics programs available, including PaintShop Pro from Jasc and Photoshop from Adobe

  20. 10 Creating a Banner Ad • To create a Web page that displays a banner ad, follow the instructions shown on pages 374 to 376 of the textbook 3

  21. 10 The CDONTS Component • The CDONTS component is an example of a third-party component • The CDONTS component is a scaled-down version of a collection of objects known as Collaborative Data Objects (CDO) • CDO is typically used to integrate your applications with active messaging systems such as Microsoft Outlook and Microsoft Exchange Services

  22. 10 The CDONTS Component • CDONTS is located in a server component called cdonts.dll, which is located in c:\winnt\system32\ and is made available when you install the Microsoft SMTP Server • The Simple Mail Transfer Protocol (SMTP) is a protocol, or set of rules, used to transfer mail between servers • SMTP Server contains several default folders, including Pickup, Queue, Badmail, Drop, and SortTemp

  23. 10 Creating Web Pages That Send E-Mail • The CDONTS component contains an object named newmail, and newmail contains a method called send, which is used to create the e-mail message and send it to the Pickup folder • The syntax shown on page 378 of the textbook shows how to create a new instance of the newmail object

  24. 10 Additional Properties of the Newmail Object • The from property is used to identify the sender • You can specify multiple recipients by using the to property • You can separate multiple recipient addresses with semicolons (;) • You can specify a “carbon copy” (CC) and a blink carbon copy (BCC) to be sent to another recipient by using the BCC property

  25. 10 Additional Properties of the Newmail Object • Blind carbon copies are used when you do not want the recipients to know that other individuals have been sent the same message • You can use the importance property to indicate to the e-mail application the importance of the message

  26. 10 Sending E-mail from a Web Page • To create a Web page that sends a static message to a single recipient perform the steps on pages 379 and 380 of the textbook

  27. 10 Sending E-mail with HTML • The newmail object allows you to send the body of your message using different formats, such as basic text and HTML • The format for the message body is basic text by default • The constant for text is CdoBodyFormatText or the number 1 • The constant for HTML is CdoBodyFormatHTML or the number 0 • To change the format to HTML, you must change the BodyFormat property of the newmail object to CdoBodyFormatHTML

  28. 10 Sending E-mail with Attachments • The newmail object has a method called AttachFile, which allows you to attach files to your e-mail messages • These attached files are often called attachments • The AttachFile method has three parameters • The location property identifies the absolute location of the attached file

  29. 10 Sending E-mail with Attachments • The Caption property is a default caption • The third property is the type of encoding • If you use the default encoding, the encoding property is optional • Default attachments are encoded with the UUEncode parameter

  30. 10 Locating Other Third-Party Software Components on the Internet • CyScape (www.cyscape.com) has created the BrowserHawk 2000 to provide additional features beyond those provided by the Browser Capabilities component • ServerObjects (www.serverobjects.com) provides several ASP components, including ASPQMail and ASPMail, which are similar to CDONTS, and are frequently used by Internet server providers to integrate ASP pages with the SMTP Server

  31. 10 Installing ASP Components • ASP components, like other software, are registered in the Windows System Registry when the program is installed • Built-in components are installed automatically when you install Internet Information Server • Microsoft provides some documentation on registering server components • You can use the Registry Installation Wizard to install the component or use the command line called Windows Regsvr32

  32. 10 Summary • ASP components are COM objects or ActiveX controls that are used with ASP pages • The Browser Capabilities component uses information from the server variable HTTP_USER_AGENT and the Browscap.ini file to determine which browser is being used, and which features the browser supports • Third party components such as BrowserHawk from cyScape are similar to the Browser Capabilities component, but maintain a more thorough list of features supported by the various browsers

  33. 10 Summary • The AdRotator component allows you to create and manage banner ads on ASP Web applications • The Rotator Schedule File maintains the default settings for all of the banner ads, and the individual settings for each banner ad • The Rotator Schedule File contains the name of the Redirection File • The method used to write the banner ad to the ASP is GetAdvertisement

  34. 10 Summary • The CDONTS component is only available if the SMTP mail server is installed • The name of the CDONTS object used to send e-mail from a Web page is CDONTS.Newmail • CDONTS can be used to send e-mail in different formats, including HTML, by altering the BodyFormat property • The AttachFile method is used to send e-mail with attachments

  35. 10 Summary • Third-party components such as ASPQMail and ASPMail are often used by hosting service providers to send e-mail from an ASP page • Third-party components are programs that are not installed when you install your Web server • You can purchase components from other companies, or write your own ASP components • ASP components can be written in a variety of software languages, including C++ and Visual Basic

More Related