Adrotator - an Advertisement File using ASP.NET

Skilled contributor
19Jan2010,11:43   #1
sameer_havakajoka's Avatar

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);
}
In AdRedirector.aspx,
Code:
<form id="form1" runat="server">
<div>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Sample.ads">
</asp:XmlDataSource> 
</div>
</form>
Go4Expert Founder
20Jan2010,10:09   #2
shabbir's Avatar
Finally moved into forum.

I guess you need to work on your code a bit harder.

Can you please explain the following lines
Code:
	String adName = string.Empty;
	String redirect = string.Empty;
	if (adName == null | redirect == null)
	{
		redirect = "Default.aspx"; 
	}
Ambitious contributor
3Feb2010,10:04   #3
seangtz's Avatar
Some of the code lines seems different .....
Skilled contributor
3Feb2010,10:51   #4
sameer_havakajoka's Avatar
differenet???
Go4Expert Member
9Jun2010,16:16   #5
dasli's Avatar
mmm...useful for me, thanks for info...