ActiveX component of ASP programming

Source: Internet
Author: User
Tags contains file system connect numeric value object model query variable
Active|activex| programming

From today onwards we will formally learn the ASP's--activex components. In fact, when you use ASP to write server-side applications, you have to rely on ActiveX components to power Web applications, such as: you need to connect to the database, do online operations on the database or operate on the Web server's file system, or you need a Web advertising exchange program, All of this you have to do by invoking the ActiveX components built into the ASP or by writing the required components yourself.

So, what exactly is an ActiveX component? And how does it work? In fact, an ActiveX component is a file that exists on a WEB server that contains code to perform an item or a set of tasks, and components can perform common tasks so that you do not have to create the code that performs those tasks yourself. For example, a stock ticker can display the latest stock quotes on a Web page. Once you have installed the ASP environment on your WEB server, you can use a few of its common components, such as the Database Access component, directly with it. Of course, you can also get optional components from Third-party developers, or you can write your own components. You can use components as scripts and basic building blocks for web-based applications, so long as you know how to access the objects provided by the component, even if you are a novice in script writing, you can write an ASP program without knowing how the component works. In summary, ActiveX components enable you to write powerful WEB server-side scripts without having to learn complex programming. If you are a developer of a bit WEB application, you can use any language that supports the Component Object Model (COM) to write 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 the MsgBox function of Visual Basic. Components can be reused. Once a component is installed on a WEB server, it can be invoked from an ASP script, an ISAPI application, another component on the server, or a program written in another COM-compliant language.

So how do we invoke components in the ASP? As mentioned earlier, a component is an executable code that is contained in a dynamic-link library (. dll) or an executable (. exe) file. A component can provide one or more objects and the methods and properties of an object. To use the object provided by the component, we first create an instance of the object and assign the new instance to the variable name. Use the ASP's Server.CreateObject method to create an instance of an object. Next, the object instance is named with the variable assignment instruction in the scripting language. When you create an object instance, you must provide the registered name "PROGID" for the instance. You will create an instance of an Ad Rotator object as follows:
% Set myads = Server.CreateObject ("MSWC.") AdRotator ")%>

We must use the ASP's Server.CreateObject method to create an object instance, and no ASP will not be able to track the use of objects in the scripting language.

You can also create an object instance using the html< object> tag, but you must supply the server value for the RUNAT property and also provide an ID attribute group for the variable name that will be used in the scripting language. You can identify the object by using a registration name (PROGID) or a registration number (CLSID). The following example uses the registration name (PROGID) to create an instance of an Ad Rotator object:
  

"OBJECT runat=server Id=myad progid=" MSWC. AdRotator ">

The common components that can be installed by ASP are listed below.

Ad Rotator Creates a AdRotator object that automatically rotates the display of advertisements on the same page as you specify. The
Browser capabilities creates a BrowserType object that determines the performance, type, and version of each browser that accesses the Web site.
Database access provides access to databases with ActiveX Data Objects (ADO). The
content linking creates a Nextlink object that generates a list of Web page content and, like a book, continues to connect pages. The
File access component provides input and output access to the file. The
Collaboration Data Objects for NTS component can quickly and easily add the ability to send and receive messages on a Web page. This component only applies to Internet information Server for Windows NT? Server. The
MyInfo creates a MyInfo object that tracks personal information, such as the name, address, and display selection of the site administrator. The
counters creates an counters object that can create, save, add, or retrieve any number of independent counters. The
Content Rotator automatically flips the HTML content string on the Web home page. The
page Counter records and displays the number of times the Web page was opened.

Now that web ads are almost all over the network, how do you create an ad system that meets the standards of advertising in your own web site? The answer is to use ASP AD rotator Components! It allows you to display new ads on the page each time you visit an ASP page, and provides strong features such as the ability to rotate the advertising image displayed on the page, the ability to track the number of times a particular ad displays, and the ability to track the number of times a client clicks on an ad. The work of the Ad Rotator component 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, and the following is a standard Ad Rotator plan file:
---adrot. TXT---
redirect/scripts/adredir.asp
WIDTH 440
Ads/homepage/chinabyte.gif
BORDER 1
>
http://www.chinabyte.com/
Check out of the IT site
2
Ads/homepage/gamichlg.gif
-
Sponsored by Flytewor KS
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 global settings for the advertisement. The Redirect line indicates that the advertisement will be the URL of its hot connection, noting that this is not the URL specified for the ad itself, but rather the URL of the middle page that will be invoked, so that we can track the number of clicks on the ad through this intermediate page. The Redirect URL is invoked with a query string that contains two parameters: the URL of a specific AD home page and the URL of an image file. The remaining three lines above the asterisk simply show how ads are displayed. The first two lines specify the width and height of the advertisement on the Web page in pixels, and the default value is 440 and 60 pixels. The following line, in pixels, specifies the border width of the four week hyperlink for the ad, and the default value is 1 pixels. If you set this argument to 0, there will be no border.

The line below the asterisk describes the details of each advertisement in one unit per four behavior. In this example, there are 16 lines, which describe four advertisements. The description of each advertisement contains the URL of the image file, the homepage URL of the advertisement (if the Advertiser does not have a home page, write a hyphen "-" on the line, indicate that the advertisement has no link) and an alternate text for the image, and a numeric value that specifies how frequently the page will be displayed alternately

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 the frequency of the ad display, you can add the weight of all the ads in the plan file, in this case the total is 10, then Aspallian's ad weight is 3, which means that the AdRotator component is displayed 3 times per call 10 times.

A redirected file is a file created by a user. It typically contains a script that resolves the query string sent by the AdRotator object and redirects the user to the URL associated with the advertisement that the user clicked. Users can also include scripts in a redirected file to count the number of users who click a particular ad and save that information to a file on the server. Increasing the number of counters and redirected users is accomplished by following two lines of ASP scripting:
%
Counter.increment (request.querystring ("url"))
Response.Redirect (request.querystring ("url"))
%>

Now that we look at how the Ad Rotator component is used in the page, you must first 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 method supported by the Ad Rotator component is getadvertisement, which has only one parameter: AdRotator the name of the plan file. Note the path to the file is the relative path from the current virtual directory, and the physical path is not allowed. The GetAdvertisement method obtains a detailed description of the next planned advertisement from the Rotator Plan file and formats it in HTML format. The following HTML is generated by the GetAdvertisement method and added to the output of the Web page 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= "/uploadpic/2007-7/200777104158743.gif" alt= "good ASP site on net" width=440 height=60 border=1>

Using the AdRotator component, we can directly control some ad properties by directly using the object properties rather than the settings in the plan file, and the available properties are as follows:

Border Specifies the size of the advertisement border.

Clickable Specifies whether the advertisement is a hyperlink.

TARGETFRAME Specifies the name of the frame that displays 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 study, I believe you have been able to skillfully use the ASP's built-in AdRotator components for their own web site to establish a standard advertising display program. Do you have any difficulty in believing that everything is so simple? In fact, the real shock to you is still behind, please pay attention to the next ASP ActiveX component Disclosure!



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.