When you use ASP to write server-side applications, you must rely on ActiveX components to powerful web applications' functions, such as: you need to connect to the database, operate the database online, etc. This article will introduce ASP ActiveX to you from this article How to use components.
Starting today, we will formally learn the best part of ASP - ActiveX components. In fact, when you write server-side applications using ASP, you must rely on ActiveX components to powerful web applications. For example, you need to connect to the database, operate the database online, or operate the file system on the WEB server. Or you need a WEB ad exchange program, all of which you must do by calling the built-in ActiveX components of ASP or writing the required components yourself.
So, what exactly are ActiveX components? How does it work? In fact, an ActiveX component is a file that exists on a WEB server. This file contains code that executes a certain item or a group of tasks. The component can perform public tasks, so that it does not have to create code that executes these tasks by itself. For example, the Stock Quotes Closing Machine component can display the latest stock quotes on the Web page. After you have installed the ASP environment on a WEB server, you can directly use several of its own commonly used components, such as the Database Access component. Of course, you can also obtain optional components from third-party developers, or write your own components. You can use components as basic building blocks for scripts and web-based applications, and as long as you know how to access the objects provided by the components, you can write ASP programs without knowing how components work. In short, ActiveX components allow you to write powerful WEB server-side scripts without learning complex programming. If you are a web application developer, you can write components in any language that supports Component Object Model (COM), such as C, C++, Java, or Visual Basic. If you are familiar with COM programming, the ActiveX component is the Automation server. However, to run on a web server, ActiveX components cannot have graphical user interface elements, such as the MsgBox function of Visual Basic. Components are reusable. Once a component is installed on a web server, it can be called from an ASP script, an ISAPI application, other components on the server, or programs written by another COM-compatible language.
So how should we call components in ASP? As mentioned earlier, components are executable code contained in dynamic link libraries (.dll) or executable files (.exe). Components may provide one or more objects as well as methods and properties of objects. To use the object provided by the component, we first create an instance of the object and assign this new instance the variable name. Use the Server.CreateObject method of ASP to create an instance of an object. Next, use the variable allocation directive of the scripting language to name the object instance. When creating an object instance, the registration name PROGID of the instance must be provided. As follows, you want to create an instance of the Ad Rotator object:
< %Set MyAds = Server.CreateObject(MSWC.AdRotator) %>
We must use the Server.CreateObject method of ASP to create an object instance, otherwise ASP cannot track the use of objects in the scripting language.
The HTML<OBJECT> tag can also be used to create an object instance, but the server value must be provided for the RUNAT attribute, and the ID attribute group must be provided for the variable names to be used in the scripting language. This object can be identified using a registration name (PROGID) or a registration number (CLSID). The following example creates an instance of the Ad Rotator object using a registered name (PROGID):
< OBJECT RUNAT=Server ID=MyAd PROGID=MSWC.AdRotator>< /OBJECT>
The following lists common components that ASP can install.
| Ad Rotator | Creates an AdRotator object that automatically rotates ads on the same page as specified. |
| Browser Capabilities | Create a BrowserType object that determines the performance, type, and version of each browser that accesses the Web site. |
| Database Access | Provides access to the database using ActiveX Data Objects (ADO). |
| Content Linking | Create a NextLink object that generates a list of web page contents and connects each page in succession like a book. |
| File Access Component | Provides input and output access to the file. |
| Collaboration Data Objects for NTS Components | It can quickly and easily add sending and receiving emails on the web page. This component is only available for Internet Information Server for Windows NT® Server. |
| MyInfo | Create a MyInfo object that tracks personal information, such as the name, address and display selection of the site administrator. |
| Counters | Creates a Counters object that can create, save, increase, or retrieve any number of independent counters. |
| Content Rotator | Automatically flip the HTML content string on the web homepage. |
| Page Counter | Record and display the number of times the web page has been opened. |
Now that WEB advertising is almost flooding the entire network, how can we build an advertising system on your own website that meets the standard functions of the advertising field? The answer is to utilize the ASP AD Rotator component! It allows new ads to be displayed on the page every time an ASP page is visited, and provides powerful features such as: the ability to rotate the ad image displayed on the page, tracking specific ads The ability to display the number of times and the ability to track the number of times a client clicks on an ad. The AD Rotator component's work is done by reading the AD Rotator plan file, which includes information about the location of the image file to be displayed and the different properties of each image. Below is a standard AD Rotator plan file :
---ADROT.TXT---
REDIRECT /scripts/adredir.asp
WIDTH 440
HEIGHT 60
BORDER 1
*
ads/homepage/chinabyte.gif
http://www.chinabyte.com/
Check out the IT site
2
ads/homepage/gamichlg.gif
-
Sponsored by Flyteworks
3
ads/homepage/asp.gif
http://www.aspallian.com/
Good ASP site on net
3
ads/homepage/spranklg.gif
http://www.clocktower.com/
The #1 Sports site on the net
2
The first four lines of this segment of code contain the global settings for the ad. The Redirect line indicates that the ad will become the URL for its hot connection. Note that this is not the URL specified for the ad itself, but the URL of the intermediate page that will be called, so that we can track the number of clicks on the ad through this intermediate page. The Redirect URL is called with a query string containing two parameters: the URL of the specific ad homepage and the URL of the image file. The other three lines above the asterisk briefly explain how to display the ad. The first two lines specify the width and height of the ad on the page in pixels, and the default values are 440 and 60 pixels. The next line also specifies the border width of the hyperlink around the ad in pixels, and the default value is 1 pixel. If this parameter is set to 0, there will be no border.
The lines below the asterisk describe the details of each ad in one unit for every four lines. There are 16 lines in this example, describing four ads. The description of each ad includes the URL of the image file, the ad's homepage URL (if the advertiser does not have a homepage, please write a hyphen on the line, indicating that the ad has no link) and alternative text for the image, and specifying the page Alternately display the frequency value with other pages.
The image is a hot connection to the redirected page, which sets two values in the query string, url=/scripts/adredir.asp and image=/ads/homepage/asp.gif. To determine how often an ad is displayed, you can add the weights of all ads in the plan file, in this case, the total is 10, and the ad weights of aspallian are 3, which means that every ten times the AdRotator component is called, it displays 3 times.
A redirect file is a user-created file. It usually contains a script that parses the query string sent by the AdRotator object and redirects the user to the URL associated with the ad the user clicks. Users can also include scripts into redirect files to count the number of users who click on a particular ad and save this information to a file on the server. Increasing the counter and redirecting the user is achieved through the following two lines of ASP scripts:
< %
Counter.Increment(request.querystring(url))
response.redirect(request.querystring(url))
%>
Now let's take a look at how the Ad Rotator component is used in the page. First, you must instantiate the Ad Rotator object using the Server.CreateObject method. The PROGID property of the Ad Rotator component is MSWC.AdRotator. The complete code is as follows:
< %Set ad = Server.CreateObject(MSWC.AdRotator) %>
< %= ad.GetAdvertisement(/ads/adrot.txt) %>
The only way the Ad Rotator component supports is GetAdvertisement, which has only one parameter: the name of the AdRotator plan file. Note that the path to the file is the relative path from the current virtual directory, and the physical path is not allowed. The GetAdvertisement method gets a detailed description of the next scheduled ad from the Rotator schedule file and formats it into HTML format. The following HTML is generated by the GetAdvertisement method and added to the output of the webpage to display the next ad in the Rotator plan file.
< A HREF=http://www.chinabyte.com/scripts/adredir.asp?http://www.aspallian.com/>< IMG
SRC=http://www.bccn.net/Article/UploadFDL0024/200409/20040912194111823.gif ALT=Good ASP site on net WIDTH=440 HEIGHT=60 BORDER=1></A>
Using the AdRotator component, we can directly control certain advertising features through object properties instead of settings in the plan file. The available properties are as follows:
Border Specifies the size of the ad border.
Clickable Specifies whether the ad is a hyperlink.
TargetFrame Specifies the name of the frame to display the ad.
< %
Set ad = Server.CreateObject(MSWC.AdRotator)
ad.Border = 0
ad.Clickable = true
ad.TargetFrame = AdFrame
ad.GetAdvertisement(/ads/adrot.txt)
%>
Through the above learning, I believe you can be proficient in using ASP's built-in AdRotator component to establish a standard advertising display program for your website. Is it hard for you to believe that everything is so simple? In fact, what really shocks you is still here. Please pay attention to the next article about the ASP ActiveX component reveal!