14. ActiveX Components

Source: Internet
Author: User
When you use ASP to write server applications, you must rely on ActiveX components to provide powerful web application functions. For example, you need to connect to the database and perform online operations on the database, this article will introduce the use of ASP ActiveX components from the beginning.

Starting from today, we will officially learn the ActiveX component, the essence of ASP. In fact, when you use ASP to write server applications, you must rely on ActiveX components to provide powerful web application functions. For example, you need to connect to the database, online Database Operations or file systems on Web servers, or you need a web ad exchange program, all of this must be done by calling ASP's built-in ActiveX components or compiling the required components.

So what is ActiveX components? How does it work? In fact, the ActiveX component is a file on the Web server. The file contains the code for executing a certain item or a group of tasks. The component can execute public tasks, in this way, you do not have to create the code to execute these tasks on your own. For example, the stock market report reader component can display the latest stock quotes on the web page. After installing the ASP environment on the Web server, you can directly use several common 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 scripts and basic construction Blocks Based on Web applications. As long as you know how to access the objects provided by components, even if you are a beginner in writing scripts, you can also write ASP programs without knowing how the components work. All in all, ActiveX components allow you to write powerful web server scripts without learning complex programming. If you are a web application developer, you can use any language that supports Component Object Model (COM) to compile components, such as C, C ++, Java, or Visual Basic. If you are familiar with COM programming, ActiveX components are automation servers. However, to run on a Web server, ActiveX components cannot have graphical user interface elements, such as Visual Basic msgbox functions. Components can be reused. After a component is installed on the Web server, the component can be called from ASP scripts, ISAPI applications, other components on the server, or programs written in another com-compatible language.

So how should we call components in ASP? As mentioned above, components are executable code contained in the dynamic link library (. dll) or executable file (.exe. A widget provides methods and attributes for one or more objects. To use the object provided by the component, we must first create an instance of the object and assign the variable name to the new instance. You can use the server. Createobject method of ASP to create an object instance. Then, use the Variable Allocation command in the script language to name the object instance. When creating an object instance, you must provide the instance Registration Name "progid ". Create an instance of the AD rotator object as follows:
<% Set myads = server. Createobject ("mswc. adrotator") %>

You must use the server. Createobject method of ASP to create an object instance. Otherwise, ASP cannot track the use of objects in the script language.

You can use the HTML <Object> tag to create an object instance, but you must provide a server value for the runat attribute and an ID attribute group for the variable name to be used in the script language. Use the Registration Name (progid) or registration number (CLSID) to identify the object. The following example uses the Registration Name (progid) to create an instance of the AD rotator object:
<Object runat = server id = myad progid = "mswc. adrotator"> </Object>

Common components that can be installed in ASP are listed below.

Ad rotator creates an adrotator object that automatically rotates ads on the same page as specified.
Browser capabilities creates a browsertype object that determines the performance, type, and version of each browser accessing the web site.
Database Access provides access to the database using ActiveX Data Objects (ADO.
Content linking creates a nextlink object, which can generate a list of web page content and connect each page as a book.
The file access component provides access to input and output files.
The Collaboration Data Objects for ETS component allows you to quickly and easily add email sending and receiving functions on the web page. This component is only applicable to Internet Information Server for Windows NT? Server.
Myinfo creates 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, add, or retrieve any number of independent counters.
Content rotator automatically flipped HTML content strings on the Web homepage.
Page Counter records and displays the number of times a Web page is opened.

Today, Web advertisements are almost full of the entire network. How can we create an advertisement system that meets the standards of the advertising field on your own website? The answer is to use the ASP ad rotator component! It allows you to display new advertisements on the ASP page each time you access the ASP page, and provides powerful functions, such: the ability to rotate the ad images displayed on the page, to track the display times of a specific AD, and to track the number of clicks of the client on the ad. The work of the AD rotator component is done by reading the ad rotator program file, which includes information related to the location of the image file to be displayed and different attributes of each image, the following is a standard ad rotator scheduler 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
-
Stored sored 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 the Code contain the global settings of the advertisement. Redirect indicates that the advertisement will become the URL of its hot connection. Note that the URL of the intermediate page will be called instead of the URL specified for the advertisement itself, in this way, we can track the number of times an advertisement is clicked on this intermediate page. This redirect URL will be called together with a query string containing two parameters: the URL of the specific ad homepage and the URL of the image file. The remaining three lines on the asterisk show how to display the advertisement. The first two lines specify the width and height of the advertisement on the webpage in pixels. The default value is 440 and 60 pixels. The last line also specifies the Border width of the hyperlink around the advertisement in pixels. The default value is 1 pixel. If you set this parameter to 0, there will be no border.

The rows under the asterisk describe the details of each advertisement in one unit for every four actions. In this example, there are 16 lines describing four advertisements. The description of each advertisement includes the URL of the image file and the homepage of the advertisement. (If the advertiser does not have a homepage, enter a hyphen "-" in the line to indicate that the advertisement has no link) and the alternative text of the image and the value that specifies the alternate display frequency between the page and other pages.

An image is a hot link to redirect pages. It sets two values in the query string: url =/scripts/adredir. asp and image =/ADS/homepage/asp.gif. To determine the frequency of AD display, you can add the weights of all ads in the plan file. In this example, the total number is 10, so aspallian's ad weight is 3, this means that the adrotator component is displayed three times every 10 calls.

A redirected file is a file created by the user. It usually contains a script used to parse the query string sent by the adrotator object and redirect the user to the URL related to the advertisement clicked by the user. You can also include the script in the redirection file to count the number of users who click a specific advertisement and save the information to a file on the server. The following two ASP scripts are used to add counters and redirect users:
<%
Counter. increment (request. querystring ("url "))
Response. Redirect (request. querystring ("url "))
%>

Now let's take a look at how the ad rotator component is used on the page. First, you must use the server. Createobject method to instantiate the ad rotator object. The progid attribute 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 method supported by the ad rotator component is getadvertisement, which has only one parameter: the name of the adrotator scheduler file. Note that the path to the file is relative to the current virtual directory, and the physical path is not allowed. The getadvertisement method retrieves detailed descriptions of the next plan advertisement from the rotator scheduler file and formats it in HTML format. The following HTML is generated by the getadvertisement method and added to the webpage output to display the next advertisement in the rotator program file.
<A href = "http://www.chinabyte.com/scripts/adredir.asp? Http://www.aspallian.com/"> Src = "http://www.chinabyte.com/ads/homepage/asp.gif" alt = "Good ASP site on net" width = 440 Height = 60 border = 1> </a>

Using the adrotator component, we can directly control some advertisement features through the object attributes instead of the settings in the plan file. Its available attributes are as follows:

Border specifies the size of the AD border.

Clickable specifies whether an advertisement is a hyperlink.

Targetframe specifies the name of the frame to display the advertisement.
<%
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 have been able to skillfully use ASP's built-in adrotator component to create a standard advertising display program for your website. Is it hard for you to believe that everything is so simple? In fact, what really shocked you is still behind the scenes. Please pay attention to the next ASP ActiveX component unveiling!

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.