Tuesday, December 04, 2007

Comment Spam Begone

{

I maintain a few personal websites, one of the closest to my heart is phoDak, a photoblog.  I wrote the site using ASP.NET about two years ago and intended it to be a low key, personal area to post pictures.  I had absolutely no validation on comments and my "what will be" attitude worked for a long time until about a week ago when I saw a comment spam link to porn right off the most recent picture.  No longer avoidable, I looked into a few ways to block unwanted comments and came up with a hybrid approach:

1. Use a photo/word as validation for a human user, just like Jeff Atwood's blog.
2. I heard about Akismet from Phil Haack who mentioned it in passing on a Dot Net Rocks episode. I found a free library and wrote about 10 lines of code:

AkismetManager akismetManager = 
new AkismetManager("my key", "my site");
string ip =
Request.ServerVariables["REMOTE_ADDR"].ToString();
if(akismetManager.IsValidKey()){
AkismetItem item =
new AkismetItem(ip, Request.UserAgent.ToString());
item.AuthorName =
CommentOwnerTextbox.Text;
item.AuthorUrl =
CommentURLTextbox.Text;
item.Content =
CommentTextbox.Text;
if(akismetManager.IsSpam(item)){
akismetManager.SubmitSpam(item);
return;
}
}

Q.E.D., really. Somewhat Mort-ish for me to lean solely on the library but it works beautifully: my spam comments since implementation remain at absolute zero.


}

No comments: