What started several upgrades to the contact Web Form were a few spam messages coming into the mail account that I have reserved for the site. These probable bots would start going on and on about driving traffic to my site, but wouldn't bother to leave any contact information. It was precisely that omission that suggested to me these messages were not being sent by people. It was after a few of these I started to look into CAPTCHA technology, and became enamored of one in particular: the Google reCAPTCHA actually uses texts from digitized books. Usually, the user is presented one word the system "knows" and one word the system does not. You type in the values that you see, and, for the word that is not known, your response is collected and compared with others; your percentage for getting the value correct is determined by the number of matching answers in the database. Getting both words right allows your operation to continue; missing one or both means taking a crack at a different pair. Ideally, the process basically affords Netizens the opportunity to correct scans of literary works, allowing them to be published digitally. Who wouldn't support that? Bots, meanwhile cannot interpret the text within a CAPTCHA; therefore, in my case, my spam traffic should drop significantly, if not completely. Google did a fairly good job at describing the mechanics of plugging the control into your .NET solution. At a high level, you start by registering your site with Google; you'll receive a private and public key pair, which you'll use when you wire up the control. Next, download the library and adding the component (a DLL) to your solution. This creates a /Bin (note the case) directory in your solution which contains Recaptcha.dll. (When you publish the site to your production server, you'll notice the dll is part of the standard /bin that contains your compiled code.) A tip to offer here: Don't download the library to someplace that's part of your development solution, like a /lib directory (just like I DID; I guess I've been working in Java too much lately). When you publish your site, that /lib directory will go up along with everything else, needlessly, unless you exclude it. Next, in your code forward, you register the control with the Web Form, and paste the code for the control inside your
(Note: if you're using master pages, then any of your content Web forms appear inside tags.) See http://code.google.com/apis/recaptcha/docs/aspnet.html for the code you'll need to copy and paste. Google offers a few different ways to implement their solution -- including a ROYO of sorts. I recommend you not look at the other means -- particularly the customization code located in http://code.google.com/apis/recaptcha/docs/customization.html. Seriously, don't look at that until AFTER you get the ASP.NET version hooked up. I will say, though, that if you view the source of what your browser renders once you have it in place, you'll see code that resembles what you'll see on that customization page. Naturally, this did not all go as smoothly and sweetly as hot milk chocolate -- BUT IT COULD HAVE. That's the main reason I'm writing this. The good news is that from the perspective of the code behind, very little was changed. One of the problems I had was that the control was returning a "false" value before any attempt to solve had been made. Although this may have been a function of other problems with this Web Form (resolved in the process of implementing reCAPTCHA), I managed this in the Page Load event handler thusly: If Not Me.IsPostBack Then Me.recaptcha.ErrorMessage = String.Empty End If One of the keys to implementing this control quickly is in doing so on a form that is already using .NET's validators, and (even better) on a form that has a submit mechanism with CausesValidation set to TRUE. If this is the case, you'll find the component will integrate seamlessly -- particularly when you believe you do not have to do a bunch of work to wire it up (BECAUSE YOU DON'T). I am responsible for having spent several hours implementing this; not Google. Honestly, just follow Google's instructions at http://code.google.com/apis/recaptcha/docs/aspnet.html and you'll likely be up and running in no time at all! ~~~~~ That should be it for now! Contact me using the site's contact form if you have questions (and see the cool new stuff!). Feel free to use the code in your projects. A shout out in your project would be thoughtful. Also, drop me a line and let me know how you might have tweaked things to better suit your needs. Finally, I wouldn't profess to be THE expert on matters represented in my code -- so drop me a line if you have constructive suggestions, too. I'd like to hear from you! Best, halfgk Copyright 2010 halfgk.com