How To use BotDetect ASP.NET CAPTCHA in Visual Studio 2003
Step 1. Create new ASP.NET Web Application
- Start Visual Studio 2003
- Select the project location, name and programming language used
Step 2. Add a BotDetect CAPTCHA reference to the project
- In the Solution Explorer, right-click the Web Application project, and Choose "Add Reference"
- Browse to the Lanap.BotDetect.dll file located in the BotDetect CAPTCHA installation folder
- The reference is added to the project's Bin folder
Step 3. Configure your site to use BotDetect CAPTCHA
- Locate the Web.config file in the Solution Explorer
Add the following lines to the <system.web> section of the "Web.config" file:
<httpHandlers> <add verb="*" path="LanapCaptcha.aspx" type="Lanap.BotDetect.CaptchaHandler, Lanap.BotDetect" /> </httpHandlers>
Step 4. Add BotDetect to the Visual Studio 2003 Toolbox for future reference.
- Right-click anywhere in the Toolbox and select "Add/Remove Items"
- Once again, browse to the Lanap.BotDetect.dll file located in the BotDetect CAPTCHA installation folder
Step 5. Add a BotDetect CAPTCHA control to a page
- Drag the newly added Captcha control from the Toolbox to the Default.aspx page
- Save all files, then compile and run the project. You will see a CAPTCHA image rendered on your web form.
Step 6. Add user input validation logic
- Add a TextBox, a Button, and a Label server control to the page
Rename the controls and set the page layout - the .aspx file fragment should look like:
<div> <BotDetect:Captcha ID="SampleCaptcha" runat="server" /> </div> <div> <asp:TextBox ID="CodeTextBox" runat="server"></asp:TextBox> <asp:Button ID="ValidateButton" Text="Validate" /> <asp:Label ID="MessageLabel" runat="server"></asp:Label> </div>
Add the following code to the Page_Load handler in the page codebehind:
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string code = CodeTextBox.Text.Trim().ToUpper(); if (SampleCaptcha.Validate(code)) { MessageLabel.Text = "Correct"; } else { MessageLabel.Text = "Incorrect"; } CodeTextBox.Text = null; } }
- Save all files, then compile and run the project. You can then try CAPTCHA validation in action
- On production web sites you will typically change the validation code to redirect the user to the resource requested if CAPTCHA validation succeeds
Sample BotDetect CAPTCHA project source code
You can find the full source code similar to the result you should get when following these instructions in the sample project coming with the BotDetect CAPTCHA installation.













