开发者网络 动网主机 支持论坛 邮局 帮助
当前位置:网络学院ASP技术打印相关 → 制作一个简单的广告系统
制作一个简单的广告系统
日期:2000年10月5日 作者: 人气:     [ ]
by Manohar Kamath
August 9, 1999

Creating a advertisement rotator page is easy - ASP comes with an Adrotator component that's easy to use.
The component, called AdRotator, is installed when you install ASP. The component has been a part of ASP
installation since the first version of ASP.

There are 3 parts to the ad rotator system:

Ad rotator logic page
Ad images date file
Redirection page
Ad rotator logic page
Create a file say ads.inc, an include file that can be included on any ASP page on your site. This file
will actually "create" the image links on the ASP pages. The page makes use of the file in item 2, the ad
images data file to choose the image from the list of images.

The code is as shown below. I created a function getAd() so that this function can be called within any
ASP page where you want the banners to show up. The advantage of putting the logic in the function is
obvious - reuseability of code.

<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
Function getAd()
  Dim loAd
  ' Create an instance of the Adrotator component
  Set loAd = Server.CreateObject("MSWC.AdRotator")

  ' Set the target frame, if any. This is the frame the where ad
  ' URL will open up. If the HTML page does not find the target name
  ' the URL will be opened in a new window
  loAd.TargetFrame = "TARGET=new"

  ' Get a random avertisement from the text file
  ' This file is in the /ad folder
  getAd = loAd.GetAdvertisement("/ad/adrotator.txt")
End Function
</SCRIPT>

Ad images data file
create the ad information file, say adrotator.txt. This file has two parts

General information for all the images - this information is applied to all images that are rotated. This
section contains 4 parts

REDIRECT - the page that will handle the redirects. you can specify a absolute or a relative URL for this
page
WIDTH - Width of the images. If not specified, defaults to 60
HEIGHT - Height of images. If not specified, defaults to 440
BORDER of the image. If not specified, defaults to 1
Individual image information. This section is separated from the first by a single "*" on a separate line
as shown in the code below. This section has four parts

Image source - either absolute, relative or a URL like http://...
Redirect URL - the URL to be sent when the user clicks on the image
Alternate text - A brief description of the ad that appears in text browsers, or when the images are
turned off
Ad weight - a number between 0 and 4,294,967,295 that determines the frequency of that ad display. A
weight of 0 means the ad will never be displayed. Higher the number, more frequent the display is.
E.g. In the example below, the weights of two images are 2 and 3. So, the second image is 3 times more
likely to appear for every 2 appearance of first.

Assuming the images are in the /images directory, a sample adrotator.txt file is shown below. The *
separates the general data from the image info. Within the images info, leave a blank line between each
image data.

REDIRECT adredir.asp
WIDTH 468
HEIGHT 60
BORDER 0
*
/images/fp2000.gif
http://www.microsoft.com/frontpage
Microsoft FrontPage 2000
2

/images/office2000.gif
http://www.microsoft.com/office
Office 2000
3

Redirection page
The redirection page, receives in its querystring, a variable named URL that contains the URL to redirect
to, and another variable IMAGE that contains the image URL of the ad image. The IMAGE variable is more for
statistical purposes, to keep count of what image appeared when and how many times etc. So, if you were to
keep count of what images were clicked, you would log this into a database (there are better ways, but
just trying to illustrate why the variable is passed).

A simple redirect page, adredir.asp, is as follows. It essentially retrieves the URL from the querystring
and does a Response.Redirect to it.

<%@language=VBScript %>
<%
  ' Set the response buffer on
  Response.Buffer = True
  Dim lsURL
  ' Obtain the URL from the querystring
  lsURL = Request.QueryString("URL")
  ' Clear the response and redirect to URL
  Response.Clear()
  Response.Redirect(lsURL)
%>

Using the system
Include the file ads.inc on any ASP page you want to show the banner ad. Then, on the page, call the
function getAd() at any point, however times you like to create as many ad banners. An example is as shown
below:

<!--#include virtual="/ad/ads.inc"-->
<HTML>
..
<!--The ad banner goes here-->
<P><%=getAd()%></P>
...
</HTML>

(出处:)

相关文章:
 
·SQL Server 2000 SP4发布
·Sql Server 2005最新CTP简介及截图
·微软发布数据库新测试版 最终版明夏登场
·网络社区论坛即将成为互联网下一热点
·SET NOCOUNT的用法和注意事项
·全正则的检测IP是否合法的函数
·判断一个access数据库中某个表是否存在的方法
·用Asp生成条形码
·数字小写到英文大写的转换
·在不支持FSO的服务器上使用XMLDOM创建HTML文件
相关软件:
 
·拓域会员核心系统 v1.02
·深博贴吧(仿百度)双数据库版 v1.5
·通用草稿自动保存系统SipoAutoSaver v2.0
·BJXSHOP网上开店专家 v6.0 SP1 Build 20060118
·企业网站智能管理系统(TZIMS) v1.5
·bzmtv v1.0 正式版
·宜兴二级域名申请系统SQL版
·Mslove交友系统 v3.0
·亿人通讯录 v3.0
·深博贴吧(仿百度)双数据库版 v1.0
说明:本站部分内容收集于网络,如有侵犯您的权益请来信告知,我们会第一时间进行处理,谢谢
 → 特别推荐
 → 热点TOP10

关于本站 | 诚聘英才 | 业务合作 | 联系我们 | 广告合作 | 收藏本站

海口动网先锋网络科技有限公司版权所有
Copyright ? 2000 - 2003 AspSky.Net
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077