Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Exteding the AdRotator Control and Advert.xml file to track advert stats

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MC - 02 Oct 2007 17:37 GMT
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?
Walter Wang [MSFT] - 03 Oct 2007 08:42 GMT
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 (wawang@online.microsoft.com, 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.
MC - 03 Oct 2007 12:56 GMT
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

> Hi MC,
>
[quoted text clipped - 18 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
MC - 03 Oct 2007 13:03 GMT
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

> Hi MC,
>
[quoted text clipped - 18 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
MC - 03 Oct 2007 23:33 GMT
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;
            }
        }
    }
}

> 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
[quoted text clipped - 36 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
Walter Wang [MSFT] - 04 Oct 2007 00:26 GMT
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 (wawang@online.microsoft.com, 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.
MC - 04 Oct 2007 00:37 GMT
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

> Hi MC,
>
[quoted text clipped - 21 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.