当前位置: 首页 > 图文教程 > 网络编程 > ASP > 动态广告管理程序制作例子

ASP
出现404页面错误的自动发送邮件的代码
ASP视频教程:建立显示已经添加的新闻页面
ASP视频教程:使用Eweb编辑器丰富新闻内容的格式
ASP视频教程:建立修改新闻页面
ASP视频教程:制作删除新闻的功能
ASP视频教程:建立产品类别表和添加类别页面
ASP视频教程:建立管理产品的页面
ASP视频教程:制作其它栏目管理页面
ASP实例教程:隐藏下载地址和防盗
ASP教程:虚拟目录下不能上传图片
ASP视频教程:制作网站前台顶部导航页面
ASP视频教程:制作前台导航菜单
ASP视频教程:对前台导航菜单进行调整美化
ASP视频教程:制作新闻中心显示页面
ASP视频教程:制作新闻详细内容显示页面
ASP视频教程:制作前台产品显示页面(按产品类别显示)
ASP视频教程:制作前台产品显示页面(横向重复显示图片)
ASP视频教程:制作在线订购页面
ASP视频教程:制作关于我们和联系我们页面
ASP视频教程:后台功能的一些完善

ASP 中的 动态广告管理程序制作例子


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 35 ::
收藏到网摘: n/a

  By Wayne Berry
This Issue
Many sites that are content specific depend on banner advertisement for revenue. Such is the case for 15
Seconds. A banner is displayed at the top of the page for every page viewed. Clients usually buy a set
number of banner impressions and these impressions are rotated amongst all the clients over a period of
time. In order to do this there must be a dynamic quality to the banners. In other words, the banner to
display is not determined until that page is requested.
With an Active Server page this is an easy task. Active Server Pages are dynamic and there are many
components that handle the task of banner rotation. A simple one comes free with the Internet Information
Server, and more complicated rotation schedules can be done with Site Server and other third party
components. This article is not about how to implement these components within your Active Server pages,
since this is a fairly easy task.

This article will describe how to implement a banner rotation scenario where the pages served are static,
i.e. .htm, and do not have the flexibility to call components. The task is to dynamically serve banners
and statically serve pages. This is the opposite of the scenario for banner rotation components, which
statically serve banners and dynamically serve pages.

One Trick
There is only one trick here and once you know it the rest is pretty straightforward. Internet Explorer
and Netscape allow you to refer to an Active Server Page within an image tag. Example 1 demonstrates the
HTML to be inserted in the static page.
Example 1 : HTML Banner Reference



< IMG SRC="http://www.myserver.com/ServeBanner.asp">


Once you have referred to a dynamic Active Server page with the static page, you need to build an Active
Server page to return an image, in this case a banner. Example 2 shows the code to use for servebanner.asp
which is called in Example 1.

Example 2 : ServeBanner.asp Source



<%
Response.Redirect("http://www.myserver.com/banner.gif")
%>


These two pages combined will allow you to display to the user a banner as if you referred directly to the
banner image instead of an Active Server page. In order to do banner rotation all you have to do is expand
Example 2 so different images come up every time ServeBanner.asp is called.

Adding the Element of Rotation.
With this technique the dynamic aspect of the banner rotation is controlled within the Active Server page
that the IMG tag is referring to. In order to randomly rotate the banners you will need to change
ServerBanner.asp to choose a different banner each time that it is called. Example 3 shows how to do this.
Example 3 : Rotating Banners



<%

Dim Array(2)

' Initialize the VBScript Random
' Number Generator
Randomize

Array(1)="http://www.myserver.com/banner1.gif"
Array(2)="http://www.myserver.com/banner2.gif"

upperbound=UBound(Array)
lowerbound=1
lRandom = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Response.Redirect(Array(lRandom))

%>


Notice that you will have to initialize the array for as many banners as are available and you will have
to assign a banner to each element of the array.

An Extra Benefit
An obvious benefit to this type of banner rotation is that fact that you don't have to serve Active Server
pages in order to have rotating banners. If the only dynamic aspect of your Active Server page is to
rotate banners you will want to change it to use this banner rotation technique, since it will reduce the
stress on your server.
It might not be so obvious that the static pages no longer need to reside on your machine to rotate
banners. For example, you could give the HTML in Example 1 to a site that you were advertising on, and
when they serve there pages w