Introductory steps for ASP programming (13): Ad & Content rotator_asp Basics

Source: Internet
Author: User
The strength of the ASP is not limited to accepting and displaying interactions, but more to using ActiveX components for more powerful Web applications.

What exactly is an ActiveX component? And how does it work? The ActiveX server components is actually 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. Very image of the word: the use of components to direct the use of other classic powerful program. It's just that the program has been encapsulated.

How does the specific ActiveX component come into being and how does it come about? The following three paths are generally available:
1, after installing the IIS server, some of the built-in components, such as the database connection component, are included.
2, get optional components from Third-party developers, or free or charge, such as some upload components (of course, there are no components to upload).
3, if you are a Web application developer, you can use the programming languages of Visual Basic, Java, Visual C + +, COBOL to write the ActiveX Server Component you need. This is the so-called ASP for COM (Component Object Model), COM + development.

Of course, whether the third party or the development of their own, before the use of the system must be registered. But these are something. What we need now is to get some of the components from the ASP as soon as possible.

However, before using the built-in components, first use a program to detect the component support in your own machine.
Refer to a popular "Arjunolic ASP Probe" on the Internet, save the following code as an ASP file for debugging viewing.

1,objcheck.asp

<%option Explicit%> <% Dim filename Filename=request.servervariables ("Script_name") Dim objtotest (14,4) Objtotest (0,0) = "MSWC." AdRotator "objtotest (0,1) =" Advertisement Wheel display Component "Objtotest (1,0) =" MSWC. ContentRotator "Objtotest (1,1) =" Content Wheel Display component "Objtotest (2,0) =" MSWC. BrowserType "Objtotest (2,1) = Browser type display component" Objtotest (3,0) = "MSWC. Nextlink "Objtotest (4,0) =" MSWC. Tools "Objtotest (5,0) =" MSWC. Status "Objtotest (6,0) =" MSWC. Counters "Objtotest (7,0) =" MSWC. IISLog "Objtotest (8,0) =" MSWC. PermissionChecker "Objtotest (9,0) =" Microsoft.XMLDOM "objtotest (10,0) =" Iissample.contentrotator "ObjTotest (11,0) =" Iissample.pagecounter "Objtotest (12,0) =" Scripting.FileSystemObject "objtotest (13,0) =" adodb.connection "public Isobj,verobj,testobj Dim i for i=0 to in error Resume Next isobj=false verobj= "testobj=" "Set Testobj=serv Er. CreateObject (Objtotest (i,0)) if IsObject (testobj) Then isobj = True verobj = testobj.version if verobj= "" or IsNull (verobj) then Verobj=testoBj.about End If Objtotest (i,2) =isobj objtotest (i,3) =verobj next sub-objtest (strobj) On Error Resume Next isobj= False verobj= "testobj=" "Set Testobj=server. CreateObject (Strobj) If IsObject (testobj) Then isobj = True verobj = testobj.version If verobj= "" or Isnu LL (verobj) then Verobj=testobj.about End If End Sub%> <title>object check</title> <table "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#cccccc" width=80%> <tr align= CENTER&GT;&LT;TD width=40%> Component Name &LT;/TD&GT;&LT;TD width=40%> related information </td></tr> <%for i=0 to 13%&gt ; <tr> <td> <%=objtotest (i,0) & " <font color= #888888 >" & Objtotest (i,1)%>& lt;/font></td> <td>  <% If not Objtotest (i,2) Then Response.Write "<font Colo R=red> does not support </font> "Else Response.Write" Support, "& Left (Objtotest (i,3), 22)End if%></td> </tr> <%next%> </table> <form action=<%=filename%> method=post> <input type=text name= "classname" size=40> <input type=submit "OK" > </FORM> value= Dim <% strclass = Trim (Request.Form ("classname")) If strclass <> "Then Response.Write" <br> Check results for the component you specified: "Dim Ver Obj1 objtest (strclass) If not Isobj then Response.Write "<br><font color=red> Unfortunately, the server does not support" & STR Class & "Components! </font> "Else if verobj=" "or IsNull (verobj) then verobj1=" Could not get the component version "Else verobj1=" the component version is: " & Verobj End If Response.Write "<br><font class=fonts> Congratulations! The server supports the "& strclass &" component. "& Verobj1 &" </font> "End If%>
[Ctrl + a All choose to copy tips: You can modify some of the code, and then click to Run]

If you can run the ASP file, that means you have the Web service for IIS. Since there is IIS, there is no accident, we have to learn the component AdRotator believe should also support.
P.S. Most of Microsoft's own MSWC starts with, and I also generally jokingly called Microsoft WC:)

One, AdRotator components
This component is often called the advertisement wheel display component, its function is equivalent to establish on the website A, conforms to the advertisement domain standard function advertisement system. It has the ability to display different ads on the page each time an ASP page is accessed, to track the number of times a particular ad is displayed, and to track how many times the client clicks on the ad.

The Ad Rotator component works by reading the Ad Rotator plan file, which includes information about where the image file is to be displayed, and the different attributes of each image. The following is a standard AD rotator plan file.

1, the type is txt text, named Myadrot.txt


REDIRECT Gourl.asp
Width 88
Height 31
Border 1
*
Yun_qi_img/logo.gif
http://www.cnbruce.com/
Cn-bruce
10

Http://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 code contain the global settings for the advertisement:

1,redirect indicates that the advertisement will be the URL of its hot connection. But its not direct JumpURL that contains a query string of two parameters: the URL of a specific AD home page and the URL of an image file. These values can then be extracted in the gourl.asp file, and at the same time gourl.asp can perform other processing tasks, such as tracking the number of clicks on the ad, jumping to the accepted advertising homepage, and so on.
2,width, height, border not to mention the width, height, and border line size of the connected picture.

The "*" symbol indicates the separator, and the details of each advertisement are described in one unit per four behavior under the "*" number. Each of them represents:

1, the description of each advertisement contains the URL of the image file
2, the Ad object's homepage URL (if the advertiser does not have a home page, then the behavior of a hyphen "-", indicating that the ad has no link)
3, alternative text of the image
4, and specifies the number of frequencies that the page alternates with other pages.

The file is a user-created file. It is usually used to parse the script of the query string sent by the AdRotator object and redirect the user to the URL associated with the advertisement clicked by the user. So how do you apply the directional file specifically?

2, adrotator.asp
The main thing about this file is to connect the Myadrot.txt file and execute the content of 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")%>"Learn the server object, I believe you remember the object of a powerful method, that is CreateObject." He can be used to create instances of ActiveX components that have been registered on the server. That means that the referencing component is mswc.adrotator.

<%=myad.getadvertisement ("Myadrot.txt")%>The only method supported by the Ad Rotator component is getadvertisement, which has only one parameter: the name of the AdRotator plan file. Note the path to the file is the relative path of the current virtual directory, and the physical path is not allowed. That means the current adrotator.asp and Myadrot.txt are in the same directory.

Then carry out the ASP file, multiple refresh, will find that every time the ads are indeed in the turn significant. Then pay attention to clicking on the hyperlink address of the picture. Like what:

Gourl.asp?url=http://www.cnbruce.com/&image=yun_qi_img/logo.gif

Obviously we also need to set up gourl.asp and extract the value of the URL parameter, and then jump to the URL address.

3, gourl.asp
This page main function: Extracts the URL parameter value, jumps to the advertisement homepage.


<%whaturl=request.querystring ("url")%>
<%response.redirect whaturl%>


The function is simple to complete. Of course, as I said earlier, this page can also do other things: tracking the number of times the client clicks on the ad, such as the cumulative number of the same URL address that will be accepted, can show the number of clicks on the site's ads, and then take the corresponding charges with The advertiser ... Oh, in the early days require the actual click-through rate, now seems like no matter, as long as the ads hanging there on the line-_-!

Overall, however, this is the function of this component. You have multiple advertisers, and are displayed separately, and you need to calculate the actual click Rate, with the Ad Rotator component is best. That means, depending on the situation.

Finally, the implementation of this component requires three files: redirect files, reference files, and process turn files.

ii. Content Rotator Components

Just as Ad Rotator is an advertisement wheel, the Content Rotator component is the contents wheel display.
The component is like a simplified Ad Rotator component, so it works as a display of the content of a Web page that is completed by reading the plan file. The plan file is the content dispatch file (Schedule).

1, the type is txt text, named Context.txt

% 3//followed by comments
<font color=red>asp Programming Introductory Step </font>

% 4//below display table
<table><tr><td>www.cnbruce.com</td></tr></table>

%% 5
<a href= "http://www.cnbruce.com" >CN-Bruce</A>


The structure of the file is simpler than the Ad Rotator dispatch file, which simply provides a list of the individual text strings to be used, as indicated by a statement line preceded by a two percent sign (%).

To set the rate of each entry (which determines how often it appears on the return page), a number is added after the double percent semicolon. If followed by a double slash (//), it is represented as an added comment.

The following is the complete display of this information in accordance with the requirements of the ASP page.

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 connection with the Content Rotator component.

" Content = mycontent.choosecontent ("Context.txt"), means that there is a way to adopt the Content Rotator component: choosecontentand assign to the variable content, and the final output displays the result.

3, showall.asp
The above page content display is implemented through the Content Rotator component's ChooseContent method. In addition, the component has one more method: getallcontent。 Examples are as follows:

<%
Set mycontent = Server.CreateObject ("MSWC. ContentRotator ")
Content = Mycontent.getallcontent ("Context.txt")
Response.Write Content
%>

The run result will find that all context.txt are interpreted and the
Of course, this method can be used in random pictures and other special effects pages.
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.