Santry Technology Solutions, Content Management, DotNetNuke, SharePoint Consulting
Register | Login
Wednesday, March 10, 2010

Sections
  
About Us
  
Partners
Downloads
  
 WWWCoder.com Resource Directory

 

ORDER TODAY!
Professional DotNetNuke ASP.NET Portals
Amazon.com now has the only DotNetNuke book you'll ever need. Written by the guys who brought you DotNetNuke, Shaun Walker, Patrick Santry, Joe Brinkman, Dan Caron, Scott McCulloch, Scott Willhite, and Bruce Hopkins. Order it now! .

Exposing DNN Banners to Other Sites
12/1/2003 8:59:52 AM

Would you like to create a cross portal banner ad campaign using the banner ad system within DotNetNuke? This article covers one way to expose your banners to other sites and be able to track the impressions and clicks using the system DotNetNuke provides.

Would you like to share your banner system with other sites? In this article we'll cover a way of displaying your banners within other sites outside of your DNN portal framework. In this example, we wanted to create some banner ad management for our directory web service. We provide the directory for free, but with the condition that the banner ads will be displayed within the directory module.

Create a Banner Script

The first thing we needed to do was to created a page to serve the banner ads. The initial idea is to create a standard html page that we will server to other sites and they then load it into an iframe that is included on their site. The use of an iframe is pretty safe nowadays since most of the major browsers supprt as part of the HTML specification.

First thing we did was to create a UI for hosting the banner ads.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ResDirAds.aspx.vb" 
Inherits="DotNetNuke.ResDirAds" validaterequest="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title runat="server" id="DocTitle">Banner Server</title>
<style type="text/css"> BODY { MARGIN: 0px } </style>
</HEAD>
<body id="Body" runat="server" MS_POSITIONING="FlowLayout" style="BACKGROUND:white" marginheight="0" marginwidth="0" leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" margin="0"> <form id="Form1" method="post" runat="server"> <asp:Panel ID="pnlModuleContent" Runat="server"> <asp:DataList id="lstBanners" runat="server" ItemStyle-HorizontalAlign="Center" EnableViewState="false" CellPadding="0"> <ItemTemplate> <span class="Normal"> <asp:HyperLink id="hypBanner" Runat="server" ToolTip=' <%# DataBinder.Eval(Container.DataItem,"BannerName") %> ' ImageUrl=' <%# FormatImagePath(DataBinder.Eval(Container.DataItem,"ImageFile")) %> ' NavigateUrl=' <%# "~/DesktopModules/Banners/BannerClickThrough.aspx?BannerId=" & DataBinder.Eval(Container.DataItem,"BannerId") %> ' Target="_Top"> </asp:HyperLink> </span> <br> </ItemTemplate> </asp:DataList> </asp:Panel> </form> </body> </HTML>
You can see in the page we have created a couple controls to store our image for our banner and another for the hyuperlink. We are going to tie these two controls into the methods provided by DNN to manager the banner ads.

In the code behind page for this aspx file we have the following:

Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Namespace DotNetNuke
  Public Class ResDirAds
    Inherits DotNetNuke.BasePage
    Protected WithEvents lstBanners As System.Web.UI.WebControls.DataList
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
                System.EventArgs) Handles MyBase.Load
      Try
        Dim intBannerTypeId As Integer
        Dim intBanners As Integer = 1
        ' Obtain PortalSettings from Current Context
        Dim _portalSettings As PortalSettings = _
            CType(HttpContext.Current.Items("PortalSettings"), PortalSettings)
        Dim objVendor As New VendorsDB
        'since we don't have an edit module for this we will hard code the 
        'the banner type we created in the database, and the number of banners to
        'display.
        intBannerTypeId = 7
        intBanners = 1
        Dim dr As SqlDataReader
        dr = objVendor.FindBanners(1, intBannerTypeId, _
             _portalSettings.PortalId, intBanners)
        lstBanners.DataSource = dr
        lstBanners.DataBind()
        If lstBanners.Items.Count = 0 Then
          lstBanners.Visible = False
        End If
        dr.Close()
      Catch ex As Exception
      End Try
   End Sub
   Function FormatImagePath(ByVal ImageFile As String) As String
     ' Obtain PortalSettings from Current Context
     Dim _portalSettings As PortalSettings = _
          CType(HttpContext.Current.Items("PortalSettings"), PortalSettings)
     If InStr(1, ImageFile, "://") = 0 Then
       ImageFile = _portalSettings.UploadDirectory & ImageFile
     End If
     Return ImageFile
   End Function
 End Class
End Namespace
Provide the IFrame Code

Then in the site you want to expose your banner ad to you need to provide their site with some iframe code to load your banner ad script.

<iframe src="http://www.wwwcoder.com/main/DesktopModules/ResDirMgr/ResDirAds.aspx"
              height=60 width=468 border=0 scrolling=no FRAMEBORDER=no></iframe>

That's all there is to it, now you can track all impressions and clicks using DotNetNuke's banner management system. The one recommendation we have here is to create a new banner type in the banner types table of DotNetNuke to provide some differentiation from your regular site ads.

By: Patrick Santry, Microsoft MVP (ASP/ASP.NET), developer of this site, author of books on Web technologies, and member of the DotNetNuke core development team. If you're interested in the services provided by Patrick, visit his company Website at Santry.com.


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970