ASP Basics Tutorial: ActiveX components

Source: Internet
Author: User

When you use ASP to write server-side applications, you must rely on the ActiveX components to powerful WEB application features, such as: you need to connect to the database, the database online operation, etc., this article from the beginning will be introduced to the ASP ActiveX component use method.

From today onwards we will formally learn the essence of ASP--activex components. In fact, when you use ASP to write server-side applications, you must rely on ActiveX components to powerful Web application functions, such as: you need to connect to the database, online operation of the database or the file system on the Web server, or you need a Web advertising exchange program, All of this you have to do by invoking an ASP built-in ActiveX component or 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 that performs a task or group of tasks, and the component can perform common tasks so that it does not have to create the code to perform those tasks on its own. For example, a stock ticker unit can display the latest stock quote on a Web page. Once you have installed the ASP environment on the WEB server, you can directly use several common components that it comes with, such as the Database Access component. Of course you can also get optional components from third-party developers, or you can write your own components. You can take advantage of components as scripts and basic building blocks of Web-based applications, as long as you know how to access the objects provided by a component, even if you are a bit of a novice in scripting, you can write an ASP program without knowing how the component works. In summary, ActiveX components allow you to write powerful WEB server-side scripts without having to learn complex programming. If you are a developer of a WEB application, you can write components using 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, an ActiveX component cannot have graphical user interface elements, such as the MsgBox function of Visual Basic. Components can be reused. After you install a component on a WEB server, you can call it from an ASP script, an ISAPI application, another component on the server, or a program written in another COM-compatible language.Shanghai Treatment Impotence Hospital}

So how do we call components in 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 the variable name. Use the ASP's Server.CreateObject method to create an instance of an object. Next, the object instance is named using the variable assignment directives in the scripting language. When you create an object instance, you must provide the registered name "PROGID" of the instance. An instance of the Ad Rotator object is created 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 cannot track the use of objects in the scripting language.
You can also create an object instance using the html< object> tag, but you must provide the server value for the RUNAT property, as well as the ID attribute group for the variable name that will be used in the scripting language. The object can be identified by using the registration name (PROGID) or registration number (CLSID). The following example creates an instance of an Ad Rotator object using the registry name (PROGID):

<object runat=server Id=myad progid= "MSWC. AdRotator "></object>
  

The common components that ASP can install are listed below.

Ad Rotator creates an AdRotator object that automatically rotates ads on the same page on a specified schedule.
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).
Content linking creates a NextLink object that generates a list of Web page contents and continues to connect pages like a book.
The file access component provides input and output access to files.
The collaboration Data Objects for NTS component makes it quick and easy to add the ability to send and receive mail on a Web page. This component only applies 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, increment, or retrieve any number of independent counters.
Content Rotator automatically flips the HTML content string on the Web home page.
Page Counter records and displays the number of times the Web page was opened.
Shanghai Treatment Impotence Hospital}
Now that web ads are almost full of networks, how do you create an ad system that meets the standard features of your ad domain on your own website? The answer is to take advantage of ASP AD rotator Components! It allows new ads to be displayed on the page each time an ASP page is accessed, and provides strong functionality, such as the ability to rotate the ad image displayed on the page, the ability to track the number of specific ad displays, and the ability to track how many clicks the client has on the 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 here 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 the code contain the global settings for the ad. The Redirect line indicates that the ad will be the URL of its hot connection, note that this is not the URL specified for the ad itself, but rather 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 that contains two parameters: the URL of the specific AD home page and the URL of the image file. The remaining three lines above the asterisk simply show how the ad is displayed. The first two lines specify the width and height of the ad on the page, in pixels, and the default value is 440 and 60 pixels. The following line, which also specifies the border width of the ad four-week hyperlink in pixels, is 1 pixels by default. 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 per four behavior. In this example, there are 16 lines that describe four ads. The description of each ad contains the URL of the image file, the page URL of the ad (if the advertiser does not have a home page, write a hyphen "-" on the line, indicate that the ad does not have a link), an alternate text for the image, and a numeric value that specifies how often the page is to be displayed alternately 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 the ad is displayed, you can add weights for all ads in the plan file, and in that case the total is 10, then Aspallian has an ad weight of 3, which means that the AdRotator component is displayed 3 times per call, 10 times.

The redirect file is a user-created file. It usually contains a script to resolve the query string sent by the AdRotator object and redirects the user to the URL associated with the ad that the user clicked. The user can also include the script in the redirect file to count the number of users who clicked on a particular ad and save that information to a file on the server. Adding counters and redirecting users is achieved through the following two lines of ASP script:

%
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, and 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:

The% 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 schedule file. Note the path to the file is a relative path from the current virtual directory, and the physical path is not allowed. The GetAdvertisement method obtains a detailed description of the next scheduled ad 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= "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 ad features directly from the object properties rather than the settings in the plan file, with the following properties available:

Border Specifies the size of the ad border.

clickable Specifies whether the ad 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 built-in AdRotator components for their own site to establish a standard advertising display program. Can't you believe it's so easy? In fact, the real shock to you is still behind, please pay attention to the next ASP ActiveX components big reveal!  

ASP Basics Tutorial: ActiveX components

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.