Tracking visitors to individual posts

Topics: ASP.NET 2.0
Sep 12, 2008 at 10:15 AM
Hi - is it possible to extend the BlogEngine to write the page/post and the user to a database, so I can track the number of people who have viewed each post?

At the moment, the system appears to create a URL which has the post as the title - and is not an acutal page - so I'm not sure where to add the code to write to the DB?

Any help would be apprciated,

Thanks, Mark
Sep 12, 2008 at 5:03 PM
Why not just use an external product like GoogleAnalytics or SiteStats?  Seems this would give you the information you need...
Sep 12, 2008 at 8:23 PM
Hi - my users are on an internal network - I thought Analytics would be a bit of overkill, when with other apps, I've just read the profile.username and the current url - I can then easily query the database to see who has read the (on the old system) newsletter.  At the moment, I've no idea if individual users are reading the blog - and as it's now intended to be our main communication channel, I need to report that 'x' number of individual people have read a specific article.

Trouble is, I'm not sure how blogengine writes the URL, or what the 'real' aspx page is that shows the posts.

Thanks, Mark
Sep 15, 2008 at 7:56 PM
I understand now... There are some pre-existing extensions that you can use that will fire when a post/page is rendered.  The main point is to hook into the Post/Page serving event:

        BlogEngine.Core.Post.Serving += new EventHandler<ServingEventArgs>(context_BeginRequest);
        BlogEngine.Core.Page.Serving += new EventHandler<ServingEventArgs>(context_BeginRequest);

From here you can use the calling function, context_BeginRequest, to perform the write out to the database/xml file you want to store the information.  If you would like some help working on this let me know.  I could probably whip up something pretty quick...

Nov 4, 2008 at 2:35 PM
Hi Chris - thank you for the offer.

I've very little idea about the code snippet you posted (where to put it, how to complete it etc), so if you could expand on it, I would certainly appreciate it.

What I was able to do, is add this to the post.aspx.cs:

string str = DateTime.Today.ToString() + "," + User.Identity.Name.ToString() + "," + Page.Title.ToString();
string FILENAME = "F:\\websites\\net2\\BlogEngine.Web\\log.csv";
StreamWriter objStreamWriter = default(StreamWriter);
objStreamWriter =

However, as the users of this are already signed in to our network, User.Identity.Name doesn't return anything.

Is there any way of reading the Windows logged on user, when using Forms authentication? (if I change authentication of BE to Windows, some admin links appear - which I don't want the users to see)

Thanks for any help,




Nov 5, 2008 at 3:39 AM
Hey Mark, can you come over to my blog and send me a message via my contact page so we can take this offline?  I'm pretty sure I can whip up something for you...