The blogroll has become a standard element on most blogs today. If it is an ASP.NET blog, the blogroll probably contains links to other ASP.NET blogs and that gives the visitor an opportunity to surf to other related websites. The only problem with it is that you have no idea what to expect from the blogs by looking at the blogroll. Most often, the link title on the blogroll contains the name of the author and if you don’t know him/her on beforehand, you have no idea if it’s a related blog or not.

That got me thinking about a way to tell a little more than just the name of the authors. Why not display the titles of their 3 latest posts so the visitor quickly can see what the blogs are about?

By showing the newest posts beneath each blog we also stop the visitor from leaving your site for an unrelated one.

The code

In order to display the latest posts we need to parse all the blog’s RSS feed, which means that we have to retrieve them first. That is time consuming, so it has to be done asynchronously so it doesn’t slow the entire page down. It doesn’t have to be updated with each request but only every hour or whenever you see fit. By each update it still mustn’t slow the page and I found a way to do that.

The first time the blogroll is created it displays the blogroll without the latest posts. After it has retrieved the feeds it adds them beneath each blog. It takes less than a second per blog and is cached until the blogroll will be updated. The default is one hour.

Implementation

The blogroll is a user control and you add blogs to it like this:

private void CreateList()
{
 AddBlog(".NET slave", "http://feeds.feedburner.com/netslave");
 AddBlog("Vault Of Thoughts", "http://vaultofthoughts.net/SyndicationService.asmx/GetRss");
}

You can set the different variables on the control itself like this:

<uc1:blogroll ID="Blogroll1" MaxLength="30" MinutesCached="60" VisiblePosts="3" runat="server" />

There are 3 properties to set:

  • MaxLength: The maximum number of characters to display for each post
  • MinutesCached: The number of minutes before it updates the posts
  • VisiblePosts: The number of posts to show beneath each blog

Download

blogroll.zip (2,66 KB)

On a small test website I’m building in my spare time, I wanted a way to count the number of clicks to the outgoing links from that site. Imaging hosting banners or other affiliate links where you get paid per click, it would be nice to know how many have clicked on them instead of relying on the advertiser’s own statistics. There are third-party products that can do it, but I would like to keep that data myself and it would be fun to build at the same time.

I came up with a very simple solution that uses a generic handler called redirect.ashx. The handler registers the clicks in an XML file and is also able to print out the stats in a nice looking table. It works by linking to redirect.ashx?url=http://example.com instead of http://example.com.

To get the stats from the handler, call it with the stats parameter redirect.ashx?stats=true. That prints out a table with the statistics from each redirected URL.

Crawlers and spiders

To avoid that the clicks made by crawlers and spiders, you can use this simple little trick that filters them out.

<a href="http://example.com" onclick="if(this.href.indexOf('redirect.ashx')==-1)this.href='redirect.ashx?url='+this.href">Click here</a>

By using the onclick event on the link, all clients that don’t support JavaScript will just follow the original URL and never hits the redirect.ashx file.

Implementation

Download the redirect.ashx handler below and put it somewhere in your web project. If your website doesn’t already have an App_Code folder in the root, then add it. That’s all you need to do. The handler automatically adds an XML file in the App_Code folder the first time it is hit and it automatically creates an XML node for every new URL it redirects.

Download

redirect.zip (1,48 KB)