ASP 3.0 Advanced Programming (23)

Source: Internet
Author: User
Tags object end error handling flush iis mail object model reference
Programming | Advanced 6th Active Server components
In the previous chapters, we have studied two different kinds of objects: one is the built-in part of the ASP object model, the other is the object provided by the Script Runtime library. This chapter describes the third class of objects that can be used for ASP, named the Active Server component (or, as a server component).
These components, in many cases, are like traditional ActiveX controls in the browser or in client script in a Visual Basic programming environment, but these components can run on the server rather than an object that can only run on the client.
The question now is: Where do these components come from? Part of this is provided by the regular Asp/iis installer, while the other part can be obtained free or paid from the web. This chapter discusses the main uses of the various components of ASP, and then describes several examples of other components that are available. Once you feel comfortable using these Active server components, you can easily embed other vendor products into your own ASP pages. A list of Third-party components is available later in this chapter, and this book also describes how to create your own components.
There are also components for ASP, but this chapter is not intended for discussion. One of the basic uses of Dynamic Web site technology is to publish information that is obtained directly from a database management system and other types of data storage, and to enable programmers to develop server-side programming by the need to collect data and store data from databases or other data stores. To accomplish these tasks using ASP, we can take full advantage of the set of components called the ActiveX Data Object (ActiveX Objects,ado) library. Because it involves a lot of content, it is difficult to elaborate in this chapter, but also to consider the other components, this book from the 8th chapter begins to tell the relevant content.
This chapter will discuss the following:
· The difference between server components and other objects that are used in ASP.
· Provides a brief description of how to instantiate an object and obtain a reference to the server component.
· ASP 3.0 and the installable components provided by IIS, such as Ad rotator, Content linking, Page counter, and tools.
· Some third party-supplied components.

6.1 Comparison of Script objects and server components
The previous chapter has illustrated the various scripting objects that are available to Asp/iis from the Script Runtime (Scrrun.dll), and it is important not to confuse these objects with the server component, the subject of this chapter.
Server components are typically implemented in their own DLLs or executables, such as the "Content linking" component that this chapter will discuss, which is implemented by Nextlink.dll. Once the DLL is installed and registered on the server, the objects it provides can be used in any scripting language supported by the ASP. The relationship between the component and the system environment is shown in Figure 6-1:
Figure 6-1 The relationship between the component and the system environment

Using Component server Components
The previous chapter has introduced the common instantiation methods of objects and components in a page. Using server components is exactly the same as using a Script Run-time library object, except that unlike script objects, server components are typically implemented as separate DLL files, and may require running an installer before use. or register the component manually (if these components are not registered at ASP's default installation).
1. CreateObject method
In general, you can create an object in an ASP page using the CreateObject method of the ASP built-in server object, for example:
Set objthis = Server.CreateObject ("This.object") ' in VBScript
Or:
var objthis = Server.CreateObject (' This.object '); In JScript
This creates a reference to the object in the variable objthis, which can then be used in a script, in other words, to control its properties and call its methods as needed in your code.
2. Using <OBJECT> elements
You can also use a regular <OBJECT> element to create an object. This method also applies to creating objects in a Web browser page. ASP supports the special implementation of the html<object> element, and we can use this method to place an object on the page. To define an instance of a component or script object in an ordinary. asp file, use the following statement:
<object runat= "SERVER" scope= "PAGE" id= "Objthis"
Classid= "clsid:oace4881-8305-11cf-9427-444553540000" >
</OBJECT>
We use the Scope property to set the scope of the object, with the options "session", "Application" and "PAGE". If you use the <OBJECT> element in an ordinary. asp file, you must use both the page attribute and the scope property, because the object you create can only be used in the page it is instantiated from. If you use the <OBJECT> element in a Global.asa file, the object you create can be used in the current session or the entire application, so the scope property can be set to sessions and application.
3. Detecting the existence of an object instance
A recurring error is an attempt to create an instance of an object that is not installed (or unregistered), or use the wrong object ProgID in the CreateObject method or <OBJECT> element. By default, an ASP error occurs and stops the page from executing.
Adding some program code to the page is necessary to detect the object before accessing it. In VBScript, you can do this by turning off the default error handling and then using the IsObject function to see if an object really refers to an object:
' In VBScript:
...
On error Resume Next ' Turn off default Error handling
Set objthis = Server.CreateObject ("This.object")

If IsObject (objthis) Then
' The CreateObject method succeeded
On Error Goto 0 ' Turn the default Error handling back on
...
' Rest of the script goes here
...
Else
Response.Write "Sorry, this page cannot is accessed at present"
Response.Flush
Response.End
End If
...
In the JScript language, you can use the new error handling features in the JScript 5.0 scripting engine, which is described in chapter 1th.
In JScript:
...
try {
var objthis = Server.CreateObject (' This.object ');
...
Rest of the script goes here
}

catch (Exception) {
Response.Write (' Sorry, this page cannot is accessed at present ');
Response.Flush ();
Response.End ();
}
...

6.2 Asp/iis Installable Components
The standard installation of Asp/iis includes a series of server components that are described as installable components (installable component) in the IIS documentation, although they are securely installed by default. But it is also possible that the name simply follows the name of the previous version of the ASP. In previous versions, these components needed to be manually installed. Now, if you want to give them an appropriate name, you can call it an "instantiated component."
It should be noted that in chapter 8th, a specific installable component, the ADO component, is described. The other components used in subsequent chapters are installed as part of a particular service or server application. For example, Collaboration Data Objects (collaborative Date Objects, CDO and CDONTS) components for mail servers and e-mail messages. The remainder of this chapter discusses how you can use other, more versatile components to provide enhancements to your Web site or intranet.
These ASP installable components can be found in the Winnt\system32\intesrv\ directory in Windows 2000, which also places configuration files that are required by the components. Some of the components are listed in alphabetical order below.
· The Ad Rotator component is used to control the appearance of clickable images, such as advertisements or titles. Using the information stored in the configuration file, Ad rotator can display a different image based on the rate specified by the profile, as well as the ability to reposition the clickable ads to the appropriate URL and to record the number of clicks on the image.
· Bro



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.