Tuesday, August 19, 2008

Ajax Toolkit NoBot Control

The Ajax Toolkit NoBot Control is a robust control for reducing the amount of spam generated from an online form. It takes a little bit of programming to get the control to function properly on the form, but it can also be extended for even greater protection.

The best place to start is to download the Toolkit with the sample website here: http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=16488. Then open up the NoBot webpage in your code editor and see how it is set up on the form. The three things to note are as follows:

  1. The NoBot control needs an inline property set for OnGenerateChallengeAndResponse set to the function in your code that will create the javascript calculation.
  2. Your code file for the page must include a reference to the AjaxControlToolkit. In C# this would be: using AjaxControlToolkit;
  3. The GenerateChallengeAndResponse function needs to be added to your code. You can copy directly from the example or provide your own.

There are a number of other ways that you can use the control to prevent spam like enforcing a maximum number of requests from an ip or a delay between a page request and post. You can read more on these properties here: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/NoBot/NoBot.aspx.