Exteding the AdRotator Control and Advert.xml file to track advertstats

M

MC

I've been using the ASP.NET ad rotator for some time and have been asked
to track the hits and click thrus, The solution that seemed obvious to
me was to extend the existing control to record the Display count and
then rewrite the URL location to be passed as a paramter to a page which
records the click count and redirect to the intended page.

This all seems to work fine. My next thought was that the most logical
location for the Click and Display count was in the Ads.xml file used to
control the AdRotator. This works however, I get Errors because the file
is locked by the AdRotator.

I currently catch the error and continue, what would be the correct way
to deal with this situation and ensure that the hit gets recorded?
 
W

Walter Wang [MSFT]

Hi MC,

My opinion on such scenario would be to use database instead of a file to
track the click count. Just insert a record for each click and later use
"select count..." to get total click count of a specific AD.

Here's some example code for your reference:

#Superexpert - Listing 4.14 - AdRotatorTrack.aspx
http://www.superexpert.com/Books/AspNet2Unleashed/Chapters/Chapter4/Listing4
_14.aspx



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

MC

True, In the past I would have agreed, however one could argue that the
XML file is a "Database" of sorts, I was trying to avoid the overheads
of another (SQL) database in my site.
The simplicity of this solution was what interested me as I already have
a sophisitcated XML file handling utility class which has meant that I
only needed to add 4 lines of code to an overriden usercontrol to
impliment the majority of the functionality.

So thanks for the Sql Solution, but I'm still interested in finding out
the recomended safe way to update the XML file that may be in use by the
AdRotator for rendering or other instances also tring to update.

Regards


Mike Caddy
 
M

MC

True, In the past I would have agreed, however one could argue that the
XML file is a "Database" of sorts, I was trying to avoid the overheads
of another (SQL) database in my site.
The simplicity of this solution was what interested me as I already have
a sophisitcated XML file handling utility class which has meant that I
only needed to add 4 lines of code to an overriden usercontrol to
impliment the majority of the functionality.

So thanks for the Sql Solution, but I'm still interested in finding out
the recomended safe way to update the XML file that may be in use by the
AdRotator for rendering or other instances also tring to update.

Regards


MC
 
M

MC

The code below is my current solution to creating a Tracked adRotator, I
hope you can agree that (along with two web.config lines) it is a very
compact solution. I have not included the XML Utility function as it
comes from a seperate library. It is this function that I think needs to
be modified?

Currently it loads the AdvertismentFile into a "XmlDocument" selects the
First node with the matching "ImageUrl" Attribute, Increments the
"DisplayCount" or "ClickCount" atribute (as Appropriate). and then saves
the document back to the file system.

There are two situations when this function fails. An Inability to load
the file because it is locked by another process and the same when saving.

Do I just have a loop with a try catch and loop until I can gain access
or time out?

Regards


MC

------------------ TrackedAdRotator.cs ------------------


using System;
using System.Web;

namespace mrc.AdRotator
{
public class TrackedAdRotator : System.Web.UI.WebControls.AdRotator
{
protected override void
OnAdCreated(System.Web.UI.WebControls.AdCreatedEventArgs e)
{
Utils.IncrementAdvertNumericAttribute(e.ImageUrl,
"ImageUrl", "DisplayCount", Page.Server.MapPath(AdvertisementFile));
if (e.NavigateUrl != "")
{
e.NavigateUrl =
string.Format("~/Adverts/AdvertHandler.ashx?Url={0}&AdvertismentFile={1}",
Page.Server.UrlEncode(e.NavigateUrl),
Page.Server.UrlEncode(AdvertisementFile));
}
base.OnAdCreated(e);
}
}

public class Redirector : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{

Utils.IncrementAdvertNumericAttribute(context.Request["Url"],
"NavigateUrl", "ClickCount",
context.Server.MapPath(context.Request["AdvertismentFile"]));
context.Response.Redirect(context.Request["Url"]);
}

public bool IsReusable
{
get
{
return false;
}
}
}
}
 
W

Walter Wang [MSFT]

Hi MC,

Even if we could update the xml file "database", there's a high chance that
we will encounter locking issues since multiple requests can take place at
the same time and they all need to write to the xml file. Note IO
operations are slow, therefore such locking and IO errors will occur very
frequently.

On the other hand, database is much better handling such concurrent
operations, especially if you're inserting two irrelevant new records
(instead of updating a single record); and database operations are much
faster than IO operations.

Hope this helps.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

MC

Ok, I agree, However the application is quite low traffic, I guess that
with time we will have more traffic and maybe the DB route is worth
doing now to save re-implimenting in the future, currently with the
simple "Try Catch Solution" there is about 2 IO errors a week.

Regards


MC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top