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 CodeThen 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.