ASP.NET, Coding

Classic ASP AdRotator

The AdRotator component is used to display a different advertisement image on a page each time a user visits or refreshes the page. A text file includes the information about the advertisement images.

Syntax for creating AdRotator Object:

<%
 set adrotator=server.createobject("MSWC.AdRotator")
 adrotator.GetAdvertisement("textfile.txt")
 %>

The text file might look like:

REDIRECT adrotator.asp
*
coderewind.gif
http://www.coderewind.com/
Visit CodeRewind
50
microsoft.gif
http://www.microsoft.com/
Visit Microsoft
25
google.gif
http://www.google.com/
Visit GOOGLE
25

The lines below the asterisk in the file “ads.txt” specifies the images to be displayed, the hyperlink addresses, the alternate text (for the images), and the display rates in percent of the hits. In the above text file the coderewind advertisement will be hit 50% of the time with microsoft or google 25% each. You can add as many ads as you can get in your server.

A free and simple AdRotator:

The following free asp adrotator code shows how to use 10 advertisements to be hit randomly as user visits your page:

  1. First you define the session(“ad”) object in the global.asa file:
  2.  
    
  3. Write the adrotator.asp file:
  4.  <% 
     if session("ad")=10 then 
        session("ad")=1 
     else 
        session("ad")=session("ad")+1 
     end if  
     %> 
     <% Select Case session("ad") %> 
      <% case 1 %> 
            
       <% case 2 %> 
            
      <% case 3 %> 
            
      <% case 4 %> 
            
      <% case 5 %> 
            
      <% case 6 %> 
            
      <% case 7 %> 
            
      <% case 8 %> 
            
      <% case 9 %> 
            
      <% case 10 %> 
            
      <% End select %>
    
  5. Include this file in all the pages of your site whereever you want the advertisements to be displayed:
  
  
 My page 
  
  
 

Welcome to CodeRewind