当前位置:首页 > ASP外文翻译+原文
ASP Banner Ad System
To the Reader from Joe: This is a user-submitted tutorial by the author above. I have read the tutorial and set the format to fit HTML Goodies, but for the most part have not changed the language. I chose this tutorial because many readers have been asking for more ASP tutorials. This is a great one.
Sorry I cannot show you the event here. The HTML Goodies servers do not offer ASP. I will tell you though that if you run IE5.0 or better, open the contents of the zip file into a directory and it runs just fine.
If you haven't already, you may want to read my introductory ASP tutorial before this one. If not, then enjoy.
There may be a point in your web design career, where your site becomes real popular. That is when companies become interested in advertising on your site. A Banner Ad system can be built to control all those advertisements that you are so willing to display, for a price. Active Server Pages makes it very easy to create a banner ad system. So easy, that the Microsoft ASP developers created an \this article, make sure you download the support material below. The files included are ad.txt
banner.asp
3 banner images clicks.asp example.asp redirect.asp ad.txt
In order for the AdRotator component to work, you must configure a text file. This text file contains all the banner ad properties. However, The text file must follow a certain format. The first four lines are as follows: REDIRECT redirect.asp WIDTH 400 HEIGHT 50 *
REDIRECT
When a banner is clicked, the \component goes to a preliminary page. This page is called a redirect page. The redirect page handles any extra programming events before directing a user to the banners destination. In this example banner system, I called the preliminary file \ WIDTH
This sets the width of the banner ad image. The value must be in pixels.
HEIGHT
This sets the height of the banner ad image. The value must be in pixels. *
The asterisk tells the \ad information. The asterisk is required.
Once you define the general properties above the asterisk, then comes the list of banners to display. In the ad.txt file, there are three banners defined below the asterisk. banner1.jpg
http://www.htmlgoodies.com HTMLGoodies.com 20
banner2.jpg
http://www.yahoo.com Yahoo.com 30
banner3.jpg
http://www.dogpile.com Dogpile.com 30
Each banner requires four lines of properties, which follow the format below: Image filename Web Address Description Banner Weight Image File
The image filename can be a fully qualified web address or relative name that points to the image. If the image is in a different folder, then you also include the folder name as well.(http://www.test.com/banner1.jpg, banner1.jpg, or foldername/banner.jpg)> Web Address
The web address can be a page on your site or a fully qualified web address that leads to another site. Description
The description will be displayed as a tool tip. When you rest your mouse over the banner, the description pops up. Banner Weight
The banner weight determines how much a banner is displayed. The \component adds all of the banner weights and determines the
probability or percent chance of a particular banner being displayed. A banner with a higher weight has better a better probability.
NOTE: You can disable a banners property by substituting with a dash. banner3.jpg -
Dogpile.com 30
The example entry above would create a banner ad that does not have a web address. Banner.asp
This file uses the \component and analyzes the contents of the ad.txt file. Below is the code. sub banner(strTarget) dim bannerad, html
set bannerad = server.CreateObject(\ bannerad.TargetFrame = strTarget
html = bannerad.GetAdvertisement(\ Response.Write html end sub
The first thing to note is that the ASP was written with VBScript. The second thing to note is that the code is written inside a sub procedure called banner(strTarget).For those of you who do not know, a sub procedure allows you to group together a bunch of code that can be reused over and over. Like a function, it takes an argument, such as a word or variable. In the code above the argument is strTarget.Unlike a function, a sub-procedure does not return any values, it just executes the code inside line by line. Inside the sub I declare two variables... dim bannerad, html
Next I store the \storing a component inside a variable you use the set keyword. Since we are programming server-side with ASP, we use server.CreateObject to summon the component. \set bannerad = server.CreateObject(\
Next I use a property of the \equivalent to:
This is the file that is processed before someone is redirected to the banners web address. Inside this file, we can capture information like how many times a particular banner is clicked and so on. To start things off, I defined a variable called \Dim strUrl Next I store a querystring value inside this new variable. strUrl = Request.Querystring(\ A querystring is nothing more than a bunch of name/value pairs attached to a web address. When a user clicks on a banner, the \component attaches a querystring to the redirect file. So if we were to click banner1.jpg, defined in ad.txt, we would end up with a redirect web address that looks like so. Redirect.asp?url=http://www.htmlgoodies.com&image=banner1.jpg In essence assigning \to \is the same as assigning http://www.htmlgoodies.com to it. Finally, I check to see which banner was clicked. I accomplish this with the VBSCript inStr( ) function. if instr(strUrl, \ Application.Lock application(\ Application.UnLock Response.Clear Response.Redirect strUrl end if The inStr( ) function returns the number position of a sub-word (sub-string) within another word (string). The format is as follows InStr(main word, sub-word) If the sub-word exist within the main word, then the function will equal a number greater-than zero or true. If the sub-word does not exist, then the function will equal zero or false. In the example above, I check to see if \exist within http://www.htmlgoodies.com. Since the answer is true, then the code inside the if... then... statement will execute.
共分享92篇相关文档