Distinct CAPTCHA Deploy steps:
The Distinct CAPTCHA Web Service is a traditional XML ASP.NET web service that you can package and deploy in multiple ways, the easiest way is to copy the files and past them to the physical web site folder under wwwroot.
How to use (Example):
This is a simple example to understand how Distinct CAPTCHA works; you can find this code from the project source code.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="DistinctCaptchaTest.TestForm" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Image ID="imgCaptcha" runat="server" /> <asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" /> <br /> <asp:TextBox ID="txtUserInput" runat="server"></asp:TextBox> <br /> <asp:CustomValidator ID="vldCaptcha" runat="server" ErrorMessage="Incorrect letters, try again" OnServerValidate="vldCaptcha_ServerValidate" ValidationGroup="submit"></asp:CustomValidator> <br /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" ValidationGroup="submit" /> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DistinctCaptchaTest.DistinctCaptchaService; namespace DistinctCaptchaTest { public partial class TestForm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GenerateImage(); } } protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { //Submit Form } } protected void btnRefresh_Click(object sender, EventArgs e) { GenerateImage(); } private void GenerateImage() { CaptchaService captchaService = new CaptchaService(); GenerateCaptcha generateCaptcha = captchaService.Generate(); imgCaptcha.ImageUrl = generateCaptcha.ImageUrl; ViewState["Tokan"] = generateCaptcha.Tokan; } protected void vldCaptcha_ServerValidate(object source, ServerValidateEventArgs args) { CaptchaService captchaService = new CaptchaService(); if (captchaService.Validate((string)ViewState["Tokan"], txtUserInput.Text)) { args.IsValid = true; } else { args.IsValid = false; } } } }