ASP programming BASICS (13): ad & content rot

Source: Internet
Author: User
Author: cnbruce resending from: 5D multimedia

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 %>
<%
Dim filename
Filename = request. servervariables ("script_name ")

Dim objtotest (14,4)
Objtotest (0, 0) = "mswc. adrotator"
Objtotest (0, 1) = "ad wheel display component"
Objtotest (1, 0) = "mswc. contentrotator"
Objtotest (1, 1) = "content wheel display component"
Objtotest (2,0) = "mswc. browsertype"
Objtotest () = "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 13
On Error resume next
Isobj = false
Verobj = ""
Testobj = ""
Set testobj = server. 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 isnull (verobj) Then verobj = testobj. About
End if
End sub
%>
<Title> object check </title>
<Table border = "1" cellpadding = "0" cellspacing = "0" style = "border-collapse :_
Collapse "bordercolor =" # cccccc "width = 80%>
<Tr align = center> <TD width = 40%> group name </TD> <TD width = 40%> correlation information </TD> </tr>
& Lt; % for I = 0 to 13% & gt;
<Tr>
<TD> <% = objtotest (I, 0) & "<font color = _
#888888> "& objtotest (I, 1) %> </font> </TD>
<TD>
<%
If not objtotest (I, 2) then
Response. Write "<font color = Red> not supported </font>"
Else
Response. Write "supported," & 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 value = "Confirm">
</Form>

<%
Dim strclass
Strclass = trim (request. Form ("classname "))
If strclass <> "" then
Response. Write "<br> check result of the component you specified :"
Dim verobj1
Objtest (strclass)
If not isobj then
Response. Write "<br> <font color = Red> sorry, this service _
The "& strclass &" component is not supported! </Font>"
Else
If verobj = "" Or isnull (verobj) then
Verobj1 = "This component version cannot be obtained"
Else
Verobj1 = "This component version is:" & verobj
End if
Response. Write "<br> <font class = fonts> congratulations! This service _
The tool supports the "& strclass &" component. "& Verobj1 &" </font>"
End if
End if
%>

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 usually 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

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. But it is not a directly redirected URL. It 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. the 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. Replace text of an image.
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 "%>" has learned about the server object. I believe you still remember the 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, which 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=UploadFiles/20046492312734.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 implementation of this component requires three files: Redirection file, reference file, and conversion file processing.

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
<Color = Red> advanced ASP programming </color>

% 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 create a contact with the content rotator component.

"Content = mycontent. choosecontent (" context.txt "", which indicates that there is a method using the content rotator component: choosecontent, which is assigned to the variable content, and finally the display result is 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 <HR> level is automatically added between categories.

Of course, this method can be used on special effects pages such as random images.

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.