Since starting this blog mid last year I have checked traffic levels a few times using the tools provided by my hosting provider (DiscountASP.NET). As expected the traffic has been pretty low. Small number of blog posts in a niche area of the internet was never going to get millions of unique monthly users.

In early December I had a quick look at my database and noticed that my latest blog post had 300+ comments. I had hit the jackpot! How could I start to cash in on all this traffic? Can I now afford a yacht? Not so fast Barry Allen!

Spam...lots of dream crushing spam! I guess it was only a matter of time.

I ran my SQL query again about 5 minutes after my first check and now I had an additional 50 comments.
Another 5 minutes...additional 100 comments.
The number of spam comments were growing exponentially.

I didn't have time to implement a solution so I just made my database read only and deleted all the spam. Horrible temporary solution but I'm paying for database storage and at the rate the spam was coming in it wouldn't have taken long before I was getting charged for additional storage.
Last night I finally got some time to put in a better solution and get comments back up and running again. I researched different solutions. I always liked the idea of CAPTCHA but always thought they looked awful and its only a matter of time before the hackers defeat the CAPTCHA algoritms. I went as far as plugging in reCAPTCHA as .Net control, but it looked so awful that I pulled it out.
Scott Hanselman mentioned that he uses a service call Akismet. If its good enough for Scott's blog then its definitely good enough for my blog.

What is Akismet?

Akismet is a web service that automatically detects comment spam. Whenever a comment is submitted to your site it's forwarded to the Akismet service first where it runs tests to determine if the comment is spam or not. Based on the thumbs up or thumbs down that it returns you can decide then not to display the comment. They have a plugin for WordPress or you can utilise their API. Since I built this blog myself I would have to use their API.

How did I use Akismet?

Before starting any coding you have to register your blog with Akismet and receive a key which is used to verify who you are when sending a comment to their service.

The code then is as simple as the following:

Akismet api = new Akismet( "MY-SECRET-KEY", "http://dopeydev.com", "DopeyDev/v1 | Akismet.Net 1.0.1";

AkismetComment c =new AkismetComment();
c.Blog = "http://dopeydev.com";
c.UserIp = comment.AuthorIP;
c.UserAgent = comment.AuthorUserAgentString;   
c.CommentContent = comment.Content;
c.CommentType = "comment";
c.CommentAuthor = comment.Author;
c.CommentAuthorEmail = comment.AuthorEmail;

var isSpam = api.CommentCheck(c);

if(!isSpam)
{
   comment.IsRejected = false;
}
else
{
   comment.IsRejected = true;
}

I uploaded this solution last night and TA-DA...no spam.

Have you used Akismet? Tell me about it!