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.

  1. Download Distinct CAPTCHA deploy package
  2. Add new web site to IIS

    Add new web site to IIS

  3. Add Distinct CAPTCHA deploy package files to the IIS web site physical path

    CAPTCHA deploy package files to the IIS web site physical path

  4. Test Distinct CAPTCHA web service

    Test Distinct CAPTCHA web service

    Test CAPTCHA web Service

    4.	Test Distinct CAPTCHA web service

 

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.

  1. Create new empty web application project using Visual studio 2010

     Create new empty web application project

  2. Add the web service reference to the project

    Add CAPTCHA web service reference

  3. Add new web form to the project, with the following controls

    Add CAPTCHA Controls


    <%@ 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>
    
    
  4. Add the following code behind
    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;
                }
            }
        }
    }
    
  5. Congratulation!

     CAPTCHA Test Page

Last edited Dec 6, 2012 at 6:42 AM by Muawiyah, version 11

Comments

ahluc08 May 4, 2015 at 5:34 PM 
I was able to add the package to the local IIS website; however, I couldn't add it under the SharePoint website on the extranet server. Please help!