News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Programming In Active Server Page - Module Two

Started by sivaji, Jan 10, 2008, 04:51 PM

Previous topic - Next topic

sivaji

Programming Stuffs in ASP - Technical Skills for INTERVIEW

Module Two

This module explains how to develop an ASP page that delivers services useful in e-commerce. This module includes the following lessons:

Rotate Ad Information. Randomly rotate ads on your Web page.

Redirect Users from Ad Links. Redirect browsers to advertisers' sites when users click on an ad image.

Count Page Hits. Track the number of times users request a page.

Rotate Ad Information

Advertising is big business on the Web. This lesson explains how to take advantage of the Ad Rotator component installed with ASP by describing how to use this component to rotate advertisements on your Web pages. The Ad Rotator component selects an advertisement for your Web page each time the user refreshes or loads the Web page. Two files are required to set up the Ad Rotator component: an Ad Rotator Include file and an ad images data file. By setting up these two files, this component can be called by any ASP page on your site. Changes to the ad parameters are not done on all the sites containing the ad, but to the ad images data file. This saves lots of time if the ad appears on numerous pages within your Web site.

This lesson explains how to:

Write an Ad Rotator Include File. Creates the ad-image links on any page that calls this file.

Create an Ad Image Data File. Specifies global ad-display data and information specific to each ad.

Test the Ad Rotator. Uses an ASP page that calls the Ad Rotator logic Include file and the image data file to display and rotate ads.

Write an Ad Rotator Include file

Include files are used to store information that will be used by more than one ASP or HTML file. By creating an Ad Rotator Include file, when changes need to be made to specific information, you only need to change the information in one location. This lesson will guide you in creating an Ad Rotator Include file containing a function named getAd(). This function randomly selects ads to display on your ASP pages. You can call this file from within any ASP page intended to display the rotated ads. When you test calling the Include file from an ASP page (see Test the Ad Rotator), you will use some images from Microsoft.com for ad images.

Open a new file in your text editor, paste in the following script, and save the file as Adrotatorlogic.inc:

<%
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
'where the 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 advertisement from the text file.

getAd = load.GetAdvertisement("adimagedata.txt")
End Function
%>

Create an ad images data file

An ad images data file is created to provide information about the ads to be displayed. By placing the data in one text file, when changes need to be made, you only need to change the data in one location. The ASP page (with the logic in the Include file) sends data in the ad images data file to the Ad Rotator component. The component then selects an ad for display.

The data file is divided into two sections that are separated by an asterisk (*). The first section provides information common to all the ads to be displayed. The second section lists data relevant to each ad.
The following outlines the structure of an ad images data file:
     
     *  REDIRECTION. URL, the path and name of the ASP file that redirects browsers that select ad images.
     *  WIDTH. The width of ad images in pixels. Default is 440.
     *  HEIGHT. The height of ad images in pixels. Default is 60.
     *  BORDER. The border thickness around ad images. Default is 1.
     *  *. Separates the first section from the second section.
     *  AdURL. Virtual path and filename of the image file containing the advertisement.
     *  AdHomeURL. URL to jump to when this link is selected. To indicate there is no link, use a hyphen.
     *  Text. Text to display if browser does not support graphics.
     *  Impressions. An integer indicating the relative weight, or probability, that this ad will be selected for display. For
         example, if two ads were displayed, one with an impression of 3 and the other with 7, then the one with 3 would have
         a 30 percent probability of being selected, while the other would have a 70 percent probability.

Open a new file in your text editor, paste in the following script, and save the file as Adimagedata.txt:

REDIRECT adrotatorredirect.asp
WIDTH 250
HEIGHT 60
BORDER 0
*    ' separates the general data from the image information
images/windows_logo.gif
http://www.microsoft.com/windows
Microsoft Windows
2
images/office_logo.gif
http://www.microsoft.com/office
Office 2000
3

Test the Ad Rotator

To test the system, you will need an ASP page that calls the Ad Rotator Include file and the ad images data file, and then displays the ads. First, you will need test ad images stored on your site.

Acquire and store the ad images as follows:
       *   Create a directory named Images in the tutorial folder: C:\Inetpub\Wwwroot\Tutorial\Images.
       *   Download the Office logo file, from the Microsoft Office Web site, and save it as Office_logo.gif in     
            C:\Inetpub\Wwwroot\Tutorial\Images.
       *   Download the Windows logo file, available at http://www.microsoft.com/windows/images/bnrwinfam.gif(, from the
            Microsoft Windows Web site, and save it as Windows_logo.gif in C:\Inetpub\Wwwroot\Tutorial\Images.

Open a new file in your text editor, paste in the following script, and save the file as Displayad.asp:

<%@ Language="VBScript" %>
<!--Call the Include file, which in turn -->
<!--calls the ad images data text file-->
<!--#include file="adrotatorlogic.inc"-->
<html>
<head>
<title>Test Ad Display Page</title>
</head>
<body>
<h1>Test Ad Display Page</h1>
<!--Display the ad banner-->
<p><%=getAd()%></p>
<p>The space above should contain an image displaying either the
   Microsoft Windows family logo or the Microsoft Office
   family logo.</p>
<ul>
<li type="disc">This indicates that Displayad.asp, Adrotatorlogic.inc,
   and Adimagedata.txt are working together to correctly display the
   images.</li>
<li type="disc">Repeatedly refreshing the page should result in the
   Windows and Office logos displaying in random order.</li>
<li type="disc">After you save Adrotatorredirect.asp, clicking on the
   displayed image should cause a new window to open, displaying the
   home page corresponding to the displayed logo.</li>
<li type="disc">After you add the hit counter script to this page,
   under "Statistics" you should see the number of page hits since
   the script was added.</li>
</ul>






<h3>Statistics</h3>
<% Set pageCount = Server.CreateObject("MSWC.PageCounter") %>
<!--Increment the counter-->
<% pageCount.PageHit %>
<p>You are visitor number <% =pageCount.Hits %> to this Web page.</p>
</body>
</html>

Redirect Users from Ad Links

When a user clicks the ad, the browser appends a query string to the request to the server. Then, the server directs the user's browser to the ad's URL.

Open a new file in your text editor, paste in the following script, and save the file as Adrotatorredirect.asp:

<%@Language=VBScript %>
<html>
<head>
<title>Redirection Page</title>
</head>
<body>
<%
'Set the response buffer on
Response.Buffer = True
Dim lsURL
'Obtain the URL from the query string
lsURL = Request.QueryString("URL")
'Clear the response and redirect to URL
Response.Clear()
Response.Redirect(lsURL)
%>
</body>
</html>

To check your work, use Displayad.asp. When you click on an ad, you should see a new window displaying an appropriate ad-related Web page.

Count Page Hits

It is important to know how many hits your Web pages get. This data helps determine how changes to your Web site may affect your customers' viewing habits. More importantly, it provides useful insight as to how customers are navigating through your site and where ads should be placed. Sites with high trafficking have higher advertisement prices associated with them. The data gathered from a page hit counter provides you with trafficking information to begin negotiating advertisement prices for your Web pages.

The Page Counter component uses an internal object to record page hit-count totals for all pages on the server. At regular intervals, this object saves all information to a text file so that no counts are lost due to power loss or system failure. The Page Counter component uses the following three methods:

         *  Hits(). This displays the number of hits for a Web page. The default is the current page.
         *  PageHit(). This increments the hit count for the current page.
         *  Reset(). This resets the hit count for a page to zero. The default is the current page.

An in-use sample of this script can be seen at the bottom of the Displayad.asp script. To place a page hit counter on a Web page, place the following script where you want the counter displayed on the page:

<% Set pageCount = Server.CreateObject("MSWC.PageCounter") %>
<% pageCount.PageHit %>
You are visitor number <% =pageCount.Hits %> to this Web site.
Am now @ Chennai