An ASP.NET Framework for Human Interactive Proofs

An article I recently wrote for MSDN online just went live:
An ASP.NET Framework for Human Interactive Proofs

It’s always fun when that happens 🙂

Comments (25)

  1. Have to say, congratulations on the article. Great coverage of a very topicval subject!

  2. Stephen Toub says:

    Thanks, Scott! Glad you like it.

  3. Mike O Shea says:

    This article seems to have covered all the current angles and is well worth the read.

  4. Anton Spass says:

    Thanks for the article, Stephen!

    Would you please point the way Words collection can be set for ImageHipChallenge. I’ve tried to set the collection using VS designer collection editor, but it throws error message [Constructor on type System.String not found].

    Thank you in advance.

  5. Stephen Toub says:

    Anton, I’ve post an answer to your question at Hope that helps.

  6. Shaun Slocumb says:

    I have recently tried to use your controls but am having trouble. The image only displays periodically but I get no errors. It displays correctly if I run the page locally or without the validator control in place but I haven’t isolated it any further. Any suggestions. Thanks

  7. PG says:

    How to get this control to work (Page_Load) inside a FormView or any other data-bound control?

    This works :



    This doesn’t:

    Dim row As FormViewRow = Me.FormView1.Row

           Dim hip As ImageHipChallenge = CType(row.FindControl("ImageHipChallenge1"), ImageHipChallenge)


    Throws the exception:

    No words available for challenge.


    protected virtual string ChooseWord()


    if (Words.Count == 0) throw new InvalidOperationException("No words available for challenge.");

    return Words[NextRandom(Words.Count)];


  8. Jim Azar says:

    Nice work this code works great for me!  

    In response to Shaun Slocumb’s post above.  I had the same problem; it works fine locally, but not when deployed to W2003 server. The problem was caused by fonts specified in ImageHipChallengeHandler.cs that were did not exist on the server. I removed "Stencil" and "Century Gothic" and now it works fine.

  9. Ben says:


    Everything works fine on my development workstation (Windows XP, VS 2005) but I get the following error when deploying on my Windows 2003 x64:


    Event code: 3005

    Event message: An unhandled exception has occurred.

    Event time: 5/14/2006 9:46:15 AM

    Event time (UTC): 5/14/2006 9:46:15 AM

    Event ID: e85d8f54977a435393eba310bcd7fcf7

    Event sequence: 164

    Event occurrence: 13

    Event detail code: 0

    Application information:

       Application domain: /LM/W3SVC/1491015058/Root/Secure-1-127920729179796735

       Trust level: Full

       Application Virtual Path: XXX

       Application Path: XXX

       Machine name: XXXX

    Process information:

       Process ID: 3948

       Process name: w3wp.exe


    Exception information:

       Exception type: TypeInitializationException

       Exception message: The type initializer for ‘Msdn.Web.UI.WebControls.ImageHipChallengeHandler’ threw an exception.

    Request information:

       Request URL: XXX

       Request path: XXX

       User host address: XXX


       Is authenticated: False

       Authentication Type:  

       Thread account name: NT AUTHORITYNETWORK SERVICE

    Thread information:

       Thread ID: 5

       Thread account name: NT AUTHORITYNETWORK SERVICE

       Is impersonating: False

       Stack trace:

    Custom event details:

    For more information, see Help and Support Center at


    any help would be greatly appreciated!

  10. This is probably due to a font not being available.  If you look in the ImageHipChallengeHandler.cs file, at the end you’ll see a static FontFamily member initialized to an array of fonts:

    private static FontFamily [] _families = {

       new FontFamily("Times New Roman"),

       new FontFamily("Georgia"),

       new FontFamily("Stencil"),

       new FontFamily("Comic Sans MS")};

    If one of those fonts isn’t available on this system, the type will fail to initialize, since this array construction is done as part of the type’s .cctor.  Try removing the line:

       new FontFamily("Stencil"),

    and see if that fixes things.  As long as there’s at least one font in this array (and as long as all of the fonts in the array are present on the machine), it should work, so feel free to change the list to whatever suits you.

  11. Dhruv says:

    Is there a sample available on the steps on how to use this ? Being a beginner but like the concept making it difficult to implement.

  12. Martin says:

    Hi Stephen,

    I’m trying to implement you’re HIP validator in a solution, however it always throws an exception in the AudioHipChallengeHandler.SpeakToFile.  The particular offending line that throws the exception is "ISpeechObjectTokens voices = speech.GetVoices(string.Empty, string.Empty)".  It throws an "Exception from HRESULT: 0x80045039", which isn’t very helpful.  I tried playing around with the SpVoice class, and I would get strange "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" exceptions.  I’m fairly confident that it’s a configuration issue, however I don’t know what I have done wrong.  I’m developing in .Net 2, in VS8 on a Windows Server 2003 enviro.  NOTE: it’s probably nothing, but I noticed that the  SpeechLib.dll version is 5.0, not the 5.1 and 5.3 that I’ve been seeing in my searches.

  13. Martin says:

    Hi Stephen,

    Ok, I resolved the issues I was having in my previous post (ensure you’re using the correct App pool with a user accout with sufficient privileges).  

    The new issue I’m having regarding this is that it creates a .wav file that is only 1k in size with no audio in it.  If anyone has any ideas how to resolve this, it would be greatly appreciated.

  14. Jonas says:

    Hi Stephen,

    Your HIP Challenge appears to work most of the time.. however occasionally the following code returns null into "string text" and there fore doesnt render a image. which seems to suggest the cache is not finding the ImageHipChallenge.ID_KEY

    this is the part of the code….

    string text = HipChallenge.GetChallengeText(new Guid(queryString[ImageHipChallenge.ID_KEY]));

               if (text != null)


                   // We successfully retrieved the information, so generate the image and send it to the client.

                   HttpResponse resp = context.Response;


                   resp.ContentType = "img/jpeg";

                   using (Bitmap bmp = GenerateImage(text, new Size(width, height)))


                       bmp.Save(resp.OutputStream, ImageFormat.Jpeg);



    any ideas on how to fix this??


  15. If the cache is being cleared, there could be several factors.  For example, memory pressure could cause resources stored in the cache to be evicted.  Or if the ASP.NET AppDomain hosting this site restarts for some reason (due to health monitoring, a change to a dependent file, etc.), the cache would also be cleared.  I’d check for signs of any of those.

  16. Ramesh says:

    I am getting error ,font famally not found please any one can send the source code for it

  17. Shivakumar says:

    where is this file ImageHipChallenge.aspx,we need to create this file ?i am not understanding

    if u got then send the file

  18. leo says:

    Can you guys post the aspx page here? Thanks

  19. pallavi says:

    i am not getting  ImageHipChallenge1.Words …where to add words?

  20. P.Romero says:

    Hi there, Ive been having problems with the Words property. The get/set statements dont seem to work as you would expect. is the following correct?




           "System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",

           "System.Drawing.Design.UITypeEditor,System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"


           public StringCollection Words




    if (_words == null) _words = new StringCollection();

    return _words;




                   _words = value;



  21. P.Romero says:

    plugging the above code into the solution produces a stringcollection editor within the designer that apparently works. However, the words colletction doesnt seem to ever get initialized, and throws the "no words available" exception at runtime.

    I know that its very bad practice to try to populate the words collection through the control properties at design-time, but I want to get it to work more as an academic exercise, and Im completely stuck as to why the Words colletction isnt being populated by the stringCollection editor.

  22. G.Magee says:

    I’m not receiving any errors.  However, the image is not showing for me at all.  I’m able to validate that the word that I set is validated, but the image is never displayed.  Can someone please let me know what might be causing this problem?


  23. Drfunkie says:

    Just use a huge ditionary file Huge.txt and randomly add a word to the imagehip collection.


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

               ‘get the LotsofWords.txt file and parse it into an array collection

               Dim intWords As Integer

               Dim objReader As New StreamReader(Server.MapPath("~/LotsofWords.txt"))

               Dim sLine As String = ""

               Dim arrText As New ArrayList

               Dim intItem As Integer = 0



                       sLine = objReader.ReadLine()

                       If Not sLine Is Nothing Then


                       End If

                   Loop Until sLine Is Nothing

               Catch ex As Exception



               End Try

    ‘Shake and Bake it baby!!



               intWords = GetRandomNumber(0, 936)

               Dim strItem As String = Nothing


                   strItem = arrText(intWords).ToString()

               Catch ext As Exception

                   strItem = arrText(5).ToString()


                   ‘add the arrtext to the hip challanger


               End Try

           End Sub

           ‘create the random object constructor using the datetime seconds

           Dim objRandom As New System.Random(CType(System.DateTime.Now.Ticks Mod System.Int32.MaxValue, Integer))

           Public Function GetRandomNumber(Optional ByVal Low As Integer = 1, Optional ByVal High As Integer = 100) As Integer

               ‘ Returns a random number,

               ‘ between the optional Low and High parameters

               Return objRandom.Next(Low, High + 1)

           End Function