Introduction
I am trying to re-solve the Hit-Counts with the help of an Ad-Rotator used as an Advertisement file using ASP.NET.
Background
The AdRotator control is used to display a sequence of ad images, which when clicked on gives the Hit-Count of the Navigation URL.
The code
Code: ASP.NET
In AdRedirector.aspx.cs
Code:
protected void Page_Load(object sender, EventArgs e)
{
String adName = string.Empty;
String redirect = string.Empty;
if (adName == null | redirect == null)
{
redirect = "Default.aspx";
}
adName = Request.QueryString["ad"];
redirect = Request.QueryString["target"];
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
String docPath = @"~/App_Data/AdResponses.xml";
doc.Load(Server.MapPath(docPath));
System.Xml.XmlElement root = doc.DocumentElement;
System.Xml.XmlNode adNode =root.SelectSingleNode(@"descendant::ad[@adname='" + adName + "']");
if (adNode != null)
{
int ctr =
int.Parse(adNode.Attributes["hitCount"].Value);
ctr += 1;
System.Xml.XmlNode newAdNode = adNode.CloneNode(false);
newAdNode.Attributes["hitCount"].Value = ctr.ToString();
root.ReplaceChild(newAdNode, adNode);
doc.Save(Server.MapPath(docPath));
}
Response.Redirect(redirect);
}
Code:
<form id="form1" runat="server"> <div> <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Sample.ads"> </asp:XmlDataSource> </div> </form>

