Using Server Objects from the Toolbox

Some interesting server-side ActiveX components are available to the Visual InterDev developer via the Server Objects tab of the Visual InterDev 6.0 Toolbox. Figure 17-4 below shows the available components. These components address common challenges facing Web developers, such as determining the type of browser that is requesting a page, sending e-mail from within ASP code, or reading and writing text files. These components can save you many hours of development time while they increase the functionality and interactivity of your applications.

Figure 17-4. The Server Objects tab of the Visual InterDev 6.0 Toolbox showing the server objects available for use in your applications.

To access the server objects on the Toolbox, all you need to do is open a new or existing ASP Web page within the Visual InterDev environment. This will enable all of the server object icons on the Server Objects tab so that you can drag them from the Toolbox onto your Web page.

NOTE
The list of objects on the Server Objects tab is predefined. This means that the list is the same no matter what workstation or server you are on. There is a chance that a server object that is displayed on the Toolbox might not actually be installed on your server. Always be sure to test your pages to ensure they are running correctly and the relevant server objects are installed on your server. The server objects are part of the IIS 4.0 installation, so if they are missing you'll want to install them from the Windows NT 4.0 Option Pack.

When you drag an object from the Server Object tab of the Toolbox onto your ASP Web page, the editor will create an <OBJECT> block for you with the correct RUNAT and PROGID attributes. After specifying the id that you would like to use for the object, you can reference it in your script. For example, if you drag a Collaboration Data Objects for Windows NT Server (CDONTS) Library NewMail object onto your Web page, the <OBJECT> block looks like this:

 <OBJECT RUNAT=server PROGID=CDONTS.NewMail id=OBJECT1></OBJECT> 

First you'll want to rename the id for the NewMail object to something more meaningful, such as oNewMail:

 <OBJECT RUNAT=server PROGID=CDONTS.NewMail id=oNewMail></OBJECT> 

Now you can reference the NewMail object in your script, as shown here:

 <% oNewMail.From = nick.evans@us.pwcglobal.com oNewMail.To = nick.evans@us.pwcglobal.com oNewMail.Subject = "CDONTS" oNewMail.Body = "This NewMail object makes sending e-mail simple!" oNewMail.Send Set oNewMail = Nothing %> 

The complete ASP code for this example would look like this:

 <@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <OBJECT RUNAT=server PROGID=CDONTS.NewMail id=oNewMail></OBJECT> <% oNewMail.From = nick.evans@us.pwcglobal.com oNewMail.To = nick.evans@us.pwcglobal.com oNewMail.Subject = "CDONTS" oNewMail.Body = "This NewMail object makes sending e-mail simple!" oNewMail.Send Set oNewMail = Nothing %> <P>&nbsp;</P> </BODY> </HTML> 

In this listing, you'll notice that the <OBJECT> block lies within the HTML source code and not within the ASP script blocks. We'll be learning more about the CDONTS objects for working with e-mail later in this chapter.

Returning to the Toolbox, you'll see that the components listed on the Server Objects tab are as follows:

  • ADO Command ActiveX Data Objects Command object for specifying the parameters necessary to execute a database command such as a SQL statement
  • ADO Connection ActiveX Data Objects Connection object for specifying the parameters necessary to make a database connection
  • ADO Recordset ActiveX Data Objects Recordset object that stores the resultset from a database command
  • Ad Rotator Automatically rotates advertisements displayed on a page according to a specified schedule
  • Browser Capabilities Determines the capabilities, type, and version of each browser that accesses your site
  • Content Linking Creates tables of contents for Web pages and links them sequentially, like pages in a book
  • My Info Creates a MyInfo object that keeps track of the site administrator's name, address, and so on
  • Dictionary VBScript object that stores data key and item pairs
  • Filesystem Object VBScript object that provides access to file input and output
  • CDONTS NewMail NewMail object for sending e-mail message; part of the Microsoft CDONTS Library
  • CDONTS Session Session object for storing session-wide settings and options; part of the Microsoft CDONTS Library
  • Index Server Query Object for writing customized queries against Index Server
  • Index Server Utility Object that provides various utilities for developers who are using the Index Server Query object
  • MSMQ Query Microsoft Message Queue Query object
  • MSMQ QueueInfo Microsoft Message Queue QueueInfo object
  • MSMQ Message Microsoft Message Queue Message object
  • MSMQ MailEMail Microsoft Message Queue MailEMail object

In addition to these components, IIS 4.0 also provides the following components that are not shown on the Toolbox but can be used nonetheless:

  • Content Rotator Similar to the Ad Rotator above but can work with any type of content—including text, images, or hyperlinks
  • Counters Creates a Counters object that can create, store, increment, and retrieve any number of individual counters
  • Page Counter Creates a PageCounter object that counts and displays the number of times a Web page has been opened
  • Permission Checker Creates a PermissionChecker object that uses the password authentication protocols in IIS to determine whether a Web user has been granted permissions to read a file
  • Status Creates a Status object that contains server status information; currently only available on Personal Web Server for Macintosh
  • Tools Creates a Tools object that has a variety of utilities

For more information on these additional components, please see the online Internet Information Server documentation within the Windows NT 4.0 Option Pack documentation. This documentation can be found by choosing Start|Programs|Windows NT 4.0 Option Pack|Product Documentation.

In this chapter, we'll take a look at some of the above components in greater detail. Since the ADO components have been covered in earlier chapters, and the MSMQ components have their own chapter, we'll concentrate on the following components:

  • Ad Rotator
  • Browser Capabilities
  • Content Linking
  • Dictionary
  • Filesystem Object
  • CDONTS NewMail
  • CDONTS Session
  • Index Server Query
  • Index Server Utility
  • Permission Checker

Sample code for all of these components is contained on the CD-ROM under the Components Web project. There's a main page named default.htm that gives you links to all of the examples. Figure 17-5 shows the main Component Samples page.

click to view at full size.

Figure 17-5. The Component Samples page from the Components Web project on the companion CD-ROM has hyperlinks to all the code samples.



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net