The strength of ASP is not limited to accepting and displaying interactions, but also to using ActiveX components for more powerful Web applications.
So What Are ActiveX components? How does it work? In fact, ActiveX Server Components (ActiveX Server Component) is a file stored on the WEB Server. This file contains the code for executing a certain task 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. A very vivid sentence: use components to directly use other classic powerful programs. However, this program has been encapsulated.
How is ActiveX components generated and obtained? It is generally obtained from the following three paths:
1. After the IIS server is installed, some built-in components, such as the Database Access Database connection component, are provided.
2. Obtain optional components from third-party developers, for example, some Upload components (of course, there are no components to upload now) for free or free of charge ).
3. If you are a Web application developer, you can use Visual Basic, Java, Visual C ++, COBOL, and other programming languages to compile the ActiveX Server Component you need. This is also known as ASP for COM (Component Object Model) and COM + development.
Of course, whether it is a third party or self-developed, you must register the system before use. However, these are all background. What we need now is to understand some of the components that come with ASP as soon as possible.
However, before using the built-in components, use a program to check the component support in your machine.
Reference a popular "A Jiang ASP probe" on the Internet and save the following code as an asp file for debugging and viewing.
1. objcheck. asp
<% Option Explicit %> <br/> <% <br/> Dim filename <br/> filename = Request. serverVariables ("SCRIPT_NAME") </p> <p> Dim ObjTotest (14,4) <br/> ObjTotest (0, 0) = "MSWC. adRotator "<br/> ObjTotest () =" ad wheel display component "<br/> ObjTotest () =" MSWC. contentRotator "<br/> ObjTotest () =" content wheel display component "<br/> ObjTotest () =" MSWC. browserType "<br/> ObjTotest () =" browser type display component "<br/> ObjTotest () =" MSWC. nextLink "<br/> ObjTotest (4, 0) = "MSWC. tools "<br/> ObjTotest (5, 0) =" MSWC. status "<br/> ObjTotest (6, 0) =" MSWC. counters "<br/> ObjTotest (7,0) =" MSWC. IISLog "<br/> ObjTotest (8, 0) =" MSWC. permissionChecker "<br/> ObjTotest (9,0) =" Microsoft. XMLDom "<br/> ObjTotest (10, 0) =" IISSample. contentRotator "<br/> ObjTotest (11,0) =" IISSample. pageCounter "<br/> ObjTotest (12, 0) =" Scripting. fileSystemObject "<br/> ObjTotest (13, 0) =" adodb. conne Ction "</p> <p> public IsObj, VerObj, testObj </p> <p> dim I <br/> for I = 0 to 13 <br/> on error resume next <br/> IsObj = false <br/> VerObj = "" <br/> TestObj = "" <br/> set TestObj = server. createObject (ObjTotest (I, 0) <br/> If IsObject (TestObj) then <br/> IsObj = True <br/> VerObj = TestObj. version <br/> if VerObj = "" or isnull (VerObj) then VerObj = TestObj. about <br/> end if <br/> ObjTotest (I, 2) = IsObj <br/> ObjTo Test (I, 3) = VerObj <br/> next </p> <p> sub ObjTest (strObj) <br/> on error resume next <br/> IsObj = false <br/> VerObj = "" <br/> TestObj = "" <br/> set TestObj = server. createObject (strObj) <br/> If IsObject (TestObj) then <br/> IsObj = True <br/> VerObj = TestObj. version <br/> if VerObj = "" or isnull (VerObj) then VerObj = TestObj. about <br/> end if <br/> End sub <br/> %> <br/> <title> Object Check </title> <br/> <tabl E border = "1" cellpadding = "0" cellspacing = "0" style = "border-collapse: collapse "bordercolor =" # cccccc "width = 80%> <br/> <tr align = center> <td width = 40%> group name </td> <td width = 40%> correlation information </td> </tr> <br/> <% For I = 0 to 13%> <br/> <tr> <br/> <td> <% = ObjTotest (I, 0) & "<font color = #888888>" & ObjTotest (I, 1) %> </font> </td> <br/> <% <br/> If Not ObjTotest (I, 2) then <br/> Response. write "<font color = Red> not supported </font> "<br/> Else <br/> Response. write "supported," & left (ObjTotest (I, 3), 22) <br/> End If %> </td> <br/> </tr> <br/> <% next %> <br/> </table> </p> <p> <FORM action = <% = filename %> method = post> <br/> <input type = text name = "classname" size = 40> <br/> <INPUT type = submit value = "Confirm"> <br/> </FORM> </p> <% <br/> Dim strClass <br/> strClass = Trim (Request. form ("classname") <br/> If strClass <> "" then <br/> Resp Onse. write "<br> check result of the specified component:" <br/> Dim Verobj1 <br/> ObjTest (strClass) <br/> If Not IsObj then <br/> Response. write "<br> <font color = red> sorry, this server does not support the" & strclass & "component! </Font> "<br/> Else <br/> if VerObj =" "or isnull (VerObj) then <br/> Verobj1 = "This component version cannot be obtained" <br/> Else <br/> Verobj1 = "This component version is: "& VerObj <br/> End If <br/> Response. write "<br> <font class = fonts> congratulations! This server supports the "& strclass &" component. "& Verobj1 &" </font> "<br/> End If <br/> End if <br/> %> <br/>
[Ctrl + A select all for copy prompt: you can modify some code before clicking run]
If you can run the ASP file, that is, you have the iis web service. The AdRotator component we want to learn today should also support IIS.
P.S. Microsoft generally comes with the beginning of MSWC.
I. AdRotator Components
This component is also known as the ad wheel display component. Its function is equivalent to setting up an advertisement system on a website that complies with the standard functions of the advertising field. It has the following capabilities: each time you access an ASP page, different ad content is displayed on the page, the ability to track the number of AD display times, and the ability to track the number of client clicks on the ad.
The active Rotator component works by reading the active 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.
1. txt text with the name myadrot.txt
Redirect gourl. asp Width 88 Height 31 Border 1 * Http://www.cnbruce.com/images/logo.gif Http://www.cnbruce.com/ CN-Bruce 10Http://www.it365cn.com/images/logo.gif Http://www.it365cn.com It365cn 10 Http://www.blueidea.com/images/logo.gif Http://www.blueidea.com Blue! Dea 10 |
The first four lines of the Code contain the global settings of the advertisement:
1. Redirect indicates that the ad will become the URL of its hot connection. HoweverNot directly jumpIt contains two query strings: the URL of the specific ad homepage and the URL of the image file. These values can be extracted from the gourl. asp file. At the same time, gourl. asp can also perform other processing work, such as tracking the number of ad clicks and redirecting to the accepted ad homepage.
2. width, height, and border are connected to the image width, height, and border size.
"*" Represents the separator, and "*" represents every four actions and one unit to describe the details of each advertisement. Which respectively represent:
1. The description of each advertisement contains the URL of the image file.
2. URL of the AD object's homepage (if the ad customer does not have a homepage, the behavior is a hyphen "-", indicating that the ad has no link)
3. substitute text for images
4, and specify the value of the frequency at which the page and other pages are displayed alternately.
This file is a user-created file. It is usually used to parse the query string script sent by the AdRotator object, and redirect the user to the URL related to the user's clicked advertisement. Then how can I apply the targeted file?
2. adrotator. asp
The most important part of this file is to connect to the myadrot.txt file and execute the information in the myadrot.txt file. Very simple. Two lines of code.
<% Set myad = Server. CreateObject ("MSWC. adrotator") %> <% = Myad. getadvertisement ("myadrot.txt") %> |
"<% Set myad = Server. CreateObject ("MSWC. adrotator") %>After learning about the Server object, I believe I still remember a powerful method of this object, that is, CreateObject. It can be used to create ActiveX component instances registered on the server. This indicates that MSWC. adrotator is referenced.
"<% = Myad. getadvertisement ("myadrot.txt") %>The only method supported by the Ad Rotator component is GetAdvertisement. It has only one parameter: the name of the AdRotator scheduler file. Note that the path to the file is the relative path of the current virtual directory, and the physical path is not allowed. Also, the former adrotator.aspand myadrot.txt are in the same directory.
Then execute the ASP file and refresh it multiple times. It will find that each advertisement is indeed remarkable in the round. Click the super connection address of the image. For example:
Gourl. asp? Url = http://www.cnbruce.com/&image=http://www.cnbruce.com/images/logo.gif |
Obviously, we also need to create gourl. asp, extract the url parameter value, and then jump to the url address.
3. gourl. asp
The main function of this page: extract the url parameter value and jump to the ad homepage.
<% Whaturl = request. querystring ("url") %> <% Response. redirect whaturl %> |
The function is simple. Of course, as I said just now, this page also supports other events: Tracking the number of times the client clicks on the advertisement, such as accumulating the numbers of accepted URLs, the number of clicks on the website advertisement can be displayed, and then the corresponding advertisers can get the corresponding fees ...... Haha, in the early days, actual click rate was required. Now it seems that no matter, as long as the advertisement goes down there -_-!
However, in general, the function of this component is like this. You have multiple advertisers, which are displayed separately in proportion. When you need to calculate the actual click rate, it is best to use the Ad Rotator component. That is to say, it depends on the situation.
Finally, the component implementation requires three files:Redirect files, reference files, and process redirection files.
Ii. Content Rotator Components
Just as Ad Rotator is an advertisement wheel display, the Content Rotator component is a Content wheel display.
This component is like a simplified Ad Rotator component, so its working principle is to display the webpage content by reading the plan file. This plan File is the Content scheduling File ).
1. txt text with the name context.txt
% 3 // followed by comments <Font color = red> advanced ASP programming </font>% 4 // The following table is displayed. <Table> <tr> <td> www.cnbruce.com </td> </tr> </table> % 5 <A href = "http://www.cnbruce.com"> CN-Bruce </A> |
The structure of this file is simpler than that of the scheduling file of Ad Rotator. You only need to provide a list of the text strings to be used, which are described by the statement line with the first two percentage signs (%.
To set the ratio of each entry (to determine the frequency of its appearance on the return page), add a number to the end of the double semicolon. If it is followed by a double slash (//), it indicates the added comment.
Then, the ASP page displays the information as required.
2. showcontext. asp
<% Set MyContent = Server. CreateObject ("MSWC. ContentRotator ") Content = MyContent. ChooseContent ("context.txt ") Response. Write Content %> |
"Set MyContent = Server. CreateObject ("MSWC. ContentRotator ")", First establish a contact with the Content Rotator component.
"Content = MyContent. ChooseContent ("context.txt ")", Indicating that there is a way to use the Content Rotator component:ChooseContentAnd assign the value to the variable Content to the final output.
3. showall. asp
The above page Content is displayed through the ChooseContent method of the Content Rotator component. In addition, this component also has a method:GetAllContent. Example:
<% Set MyContent = Server. CreateObject ("MSWC. ContentRotator ") Content = MyContent. GetAllContent ("context.txt ") Response. Write Content %> |
The result shows that all contents of context.txt are interpreted and executed, and the
Of course, this method can be used on special effects pages such as random images.