Use of adrotator in asp.net counting number of clicks on banner ad

95

By gauri1234

An Ad rota-tor in asp.net is used to create advertisements like banners and add responses to them. For eg we can know how many time the banner is clicked just like google ad sense does.

How to create it

open a new website in visual studio dot net file-> new website name it advertisehere.aspx

right click on solution explorer and add new folder. Create three images in paint a1.bmp a2.bmp a3.bmp

add these images to the images folder ..right click on images folder and select "add exisiting item."

create an xml file by right clicking in solution explorer .."add new item" select xml file and put the following code.



xml file

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <!-- The URL for the ad image -->
    <ImageUrl>images/a1.bmp</ImageUrl>
    <!-- The URL the ad redirects the user to -->
    <NavigateUrl>http://www.microsoft.com</NavigateUrl>
    <!-- The alternate text for the image -->
    <AlternateText>Visit Microsoft's Site</AlternateText>
    <!-- The relative number of times this ad should appear -->
    <!-- compared to the others -->
    <Impressions>80</Impressions>
    <!-- The topic of this ad (used for filtering) -->
    <Keyword>ProductInfo</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>images/a2.bmp</ImageUrl>
    <NavigateUrl>http://www.microsoft.com/technet</NavigateUrl>
    <AlternateText>Support for IT Professionals</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>Support</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>images/a3.bmp</ImageUrl>
    <NavigateUrl>http://msdn.microsoft.com</NavigateUrl>
    <AlternateText>Support for developers</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>Support</Keyword>
  </Ad>
</Advertisements>

save this xml file as adverts.xml.


Add ad rotator control from tool box. click the control press f4 and in properties window in advertisement file option put adverts.xml

Add a new web page(add new item) adsforyou.aspx and add the following code after pressing f7 for code behind file(remember we are working on vb based asp.net)

in the adpath.txt file you will get the report of the clicks. You thus know when the banner is clicked!


Partial Class adsforyou
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object,_
 ByVal e As System._
EventArgs) Handles Me.Load
        Try
            Dim strAdPath As String

            'Get the URL to navigate to.
            strAdPath = Request.QueryString(_
"Adpath")

            'Log the ad click to a text file 
(you can use a database).
            Dim AdFile As New IO.FileInfo
(Server.MapPath("AdResponse.txt"))
            Dim AdData As IO.StreamWriter
            AdData = AdFile.AppendText
            AdData.WriteLine(Now().ToString & ": 
Ad clicked. 
Redirect to " & _
             strAdPath)
            AdData.Close()

            'Redirect the user to the ad URL.
            Response.Redirect_
(strAdPath)
        Catch ex As Exception
            ex.Message.ToString()
        End Try



    End Sub
End Class

it may not work until you do this:

add the following code to the main web page advertisehere.aspx after double clicking on the adrotator control dropped from toolbox on to the page


Partial Class advertisehere
    Inherits System.Web.UI.Page

    Protected Sub AdRotator1_AdCreated_
(ByVal sender As Object,_
ByVal e As System.Web.UI.WebControls._
AdCreatedEventArgs)_
 Handles AdRotator1._
AdCreated
        e.NavigateUrl = "adsforyou.aspx?Adpath=" _
& e.NavigateUrl

    End Sub
End Class
'this will be advertisehere.aspx.vb

Comments

fatma78 7 months ago

Good article

I have found good website for Microsoft.Net professional www.dotnettechy.com here we can search articles, Problem and solutions and interview questions and answer.

We can also bookmark for further reference.

Also we can submit and manage .net articles URLs, problems, and interview questions.

www.dotnettechy.com

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    • No HTML is allowed in comments, but URLs will be hyperlinked
    • Comments are not for promoting your Hubs or other sites

    Please wait working