Ramblings & Controls from a .NET Addicted Freak!

Kevin Gearing's Blog

July 2007 - Posts

  • FormShield v2.0.1 Released

    FormShield v2.0.1 has been released. Click here for details.

  • Adding a License Key to FormShield

    If you're reading this, you've probably sent a donation for FormShield - Thank you - It's much appreciated!

    Ok, follow the instructions below to add the license key you've been e-mailed to FormShield:

    Open up your 'web.config' file and where you currently have:

    <add key="formShield_SecretKey" value="!--FormShield--!" />


    add the following directly beneath the 'formShield_SecretKey' line (not instead of!), replacing 'MyKey' with the key that was e-mailed to you (leave the double quotes in place).

    <add key="formShield_LicenseKey" value="MyKey" />

    That's it.

    Save and upload the web.config file and FormShield will no longer render the '' adverts.

    Thanks again for donating!

  • Adding FormShield to Community Server 2007 - Blog Comments

    Adding FormShield to the blog comments area of Community Server 2007 is fairly straightforward.

    Brief instructions are below, I've also uploaded a copy of the 'post.aspx' and 'web.config' files showing these changes to here.

    1. Download the 'web.config' file for the site and add the following before <connectionStrings ... />:

    <add key="formShield_SecretKey" value="!--FormShield--!" />


    2. Also in the 'web.config' file, add the following in the <httpHandlers ... /> area:

    <add verb="GET" path="FormShield.aspx" type="dotNetFreak.WebControls.FormShieldHttpHandler, dotNetFreak.WebControls.FormShield" />

    3. Copy the 'dotNetFreak.WebControls.FormShield.dll' and 'dotNetFreak.WebControls.FormShield.BritishMale8kHz8bitMonoWavSoundLibrary.dll' files to the 'bin' directory.

    4. Download the 'post.aspx' file for the theme you are using - e.g. '/Themes/Blogs/default/post.aspx'.

    5. At the top of the file underneath '<% Page Language="C#" ... /> add:

    <%@ Register Assembly="dotNetFreak.WebControls.FormShield" Namespace="dotNetFreak.WebControls" TagPrefix="dnf" %>

    6. Scroll down in the file until you see:

    <div class="CommonFormField" id="Remember" runat="server">

    <asp:CheckBox id="chkRemember" runat="server" Text="Remember Me?" />


    Then add the following directly beneath it:


    <br />

    <dnf:FormShield ID="FormShield1" runat="server" HttpHandlerPath="/FormShield.aspx" PersistenceMethod="ControlState">

    <RefreshIcon AlternateText="Refresh" />

    <SoundIcon AlternateText="Listen" />

    <HelpIcon AlternateText="Please enter the characters shown on the image" />


    <br /><br />

    Code: <asp:TextBox ID="TextBox1" width="208px" runat="server" />

    <br /><br />

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please enter the code." Display="Dynamic" ValidationGroup="CreateCommentForm" />

    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="FormShield1" ControlToValidate="TextBox1" EnableClientScript="False" ErrorMessage="Invalid code entered." Display="Dynamic" ValidationGroup="CreateCommentForm" />

    <br />


    7. Save and upload the files and you are done!

  • Firefox, BinaryWrite and Compression

    Whilst writing the sound support for FormShield v2, I came across quite an interesting issue, well it was interesting once I'd found the answer, but up until then I wasn't in the best of moods.

    Basically, FormShield uses the BinaryWrite() method to write an audio file to the requesting browser to provide sound support. The issue was that this worked fine in IE, Safari and Opera, but for some reason Firefox didn't seem to like it.

    The strange thing about it was that it would play the first x number of characters, but then stop. On a Mac, it would only play the first character before giving up.

    Thinking that it must be something to do with how I was writing the file out, or perhaps the file size, or even my code that builds the sound file, I started to pull the code apart.

    A few hours later, I was no further forward.

    I came to the conclusion that it couldn't be my code, after all, writing images out this way seemed to work fine in every browser.

    So, I started to look around the problem. I then stumbled across an old post related to writing out PDF files on the fly using BinaryWrite and whilst the issue didn't see to be the same, or affect the same browser (they were talking about IE), one word was mentioned that rang a bell - "Compression".

    I suddenly remembered that HTTP compression was enabled in IIS on this particular server - Quickly turning it off and running an 'iisreset' and testing resulted in a perfect playback.

    Thankfully all of the code I changed was only a CTRL-Z away from being put back to how it was originally and 10 minutes later I retested it and it worked fine.

    So, why does HTTP compression in IIS only break Firefox? No idea - After spending seven hours on the problem I really couldn't care.

  • FormShield and Donationware

    One question I'm bound to be asked is why have I made FormShield v2.0 donationware rather than commercial and why haven't I continued to offer it for free.

    Well, starting at the end first - FormShield is still totally free for personal and commercial use and you are still able to distribute it with your applications without 'donating' a penny (or dime), providing you don't charge for it of course!

    Ok, so if it's free why the ' adverts'?

    Well, when something is offered for free (or donationware), it's too easy to just take it, use it and forget about it. I've done it, you've done, everyone does it. By having a couple of 'gentle' reminders, it prompts us to think "Actually I do use this a lot more than I initially thought, I'm going to pay something for this". Of course that's the idea, whether it works or not is another matter!

    If it doesn't, I should at least end up with more people using FormShield and hopefully some of them will donate!

    Why donationware?

     The idea behind making FormShield donationware is simple:

    • Some people have suggested it as they would like to contribute towards future development of FormShield and other controls.
    • FormShield is a complex control and because of this it has taken a large amount of time to create.
    • I don't get paid for doing this - in fact it actually costs me money!
    • I didn't want to restrict the overall functionality of FormShield.

    Why not commercial?

    The problem with making anything commercial is it removes it from the realm of being a hobby which is all my controls are at the end of day. Yes, they were initially written for other projects, but those projects didn't need me to write new versions. Also, I don't have time to support another commercial venture, I spend most of my time working as it is! I also hate writing documentation and examples, both of which I would need to do to make FormShield commercial.

    I also didn't want to stop the smaller Web sites and hobbyists from using FormShield because they couldn't afford to pay the 'commercial' (per Web site in some cases) license fees.

    Right, so it's totally free if I don't mind the occasional '' advert?


    Are all of your existing controls and future controls moving to donationware?

    No. Only FormShield, but if you want to send a donation for the others please feel free!

    If I release future controls (quite likely as I'm starting a new project shortly which will probably require custom controls) they may or may not be donationware. More than likely the first versions won't be.

    I want to donate - How much?

    Firstly, thank you!

    Secondly, whatever you want. Its not that I don't care how much you donate, I don't know your circumstances or how widely you use my controls. If you're working for a Web design agency and you use my controls on two hundred Web sites, perhaps you should be thinking more than the one guy who adds it to his blog, but at the end of the day it's entirely up to you, I'm just happy you're going to donate!

  • FormShield for .NET 2.0 Released

    FormShield started out as a simple project with just one aim - to prevent automated form submission using dynamically generated images.

    Not exactly a new idea - dynamically generated images requiring the user to enter the text found on the image have been around for quite a while, preventing automated sign-ups to free e-mail services such as HotMail and Yahoo, and automated whois lookups on domain names on sites such as Network Solutions.

    Whilst some code exists on Code Project, there didn't however seem to be a free, easy-to-use and customisable control for ASP.NET with full designer integration that could generate the relevant images. So, looking for an excuse to delve into GDI+, FormShield was born and my idea of a 'simple' control was dropped...

    ... That was 2004 and this is now...

    Version 2 of FormShield builds on the previous .NET 1.1 version, adding a wealth of new features, options and accessibility improvements. The most notable feature addition is the capability for FormShield to now automatically generate a spoken version of the value shown on the image to aid with accessibility legal compliance. This however is just one of a handful of major new features, not to mention the number of improvements and changes made since the previous version.

    However, whilst a lot has changed, FormShield remains true to its original goals - to be 'easy-to-use', 'customisable' and to have 'full designer integration'.

    No other .NET captcha control currently on the market has the number of features of FormShield, but more importantly, none of them are as customisable or have such a rich design-time experience when used in Visual Studio.

    For more information, check out What's New in Version 2.0.


    • Generates BMP, GIF, JPEG or PNG images.
    • Choose the pixel format and smoothing mode used to render the image.
    • Set the height and width of the image as well as the alternate text displayed.
    • Image is built using 3 layers - Background, foreground and noise.
    • Provides 5 fill styles, 5 gradient styles, 54 hatch styles and 2 colors for each layer.
    • Set the length (static or random*) and case (lower, mixed or upper) of the automatically generated text.
    • Ability to set your own text for FormShield to use and the ability to regenerate or automatically change it on postback*.
    • Choose the type of characters you want to use to generate the text (alpha, numeric, symbols, a combination, or random).
    • Choose the fonts (when using a font based text effect) you want to use to draw the text (26 as default) as well as the font style (5 combinable styles, 17 in total).
    • Choose the default, static font to use to draw the text when not using a font based text effect*.
    • Pick a text effect (5 combinable effects, 25 in total) and decrease the noise level to decrease readability.
    • Draw a border around the image using one of 5 styles and your choice of color and width.
    • Randomise the fill style, gradient style, hatch style, font style, text case, character type, text effect and border style.
    • 6 Presets included; Default, Fire, Forest, Sand, Sea and ChessBoard.
    • Supports 4 persistent methods; ViewState, ControlState*, SessionState or HiddenField - ideal if ViewState and/or SessionState aren't available to persist property values on postback.
    • Values stored using any of the persistent methods are automatically encrypted for additional security (128 bit encryption*) with the ability to add your own key to the web.config file*.
    • ValidFrom and ExpiresAfter properties to set how many seconds have to pass before the image is valid and how many seconds after which the image has expired* - Prevent replay attacks.
    • ImageClick event raised when someone clicks on the image (supports Regenerate to generate a new value, BubbleEvent to bubble the event for custom handling or both)*.
    • Full embedded sound support (2 voices as standard, 8bit or 16bit and 8kHz or 16kHz - all selectable) - Will prompt to download the audio file if no plugin is installed.*
    • SoundLibraries distributed seperately so you only need to copy the one you require to your bin directory.*
    • Three additional icons rendered with customisable properties (AlternateText, Height, Width, IconUrl, Visible). Renders default icons if IconUrl is empty.*
    • Refresh icon to automatically regenerate the text value (can also raise an event for custom handling), Sound icon for built in audio playback and Help icon with customisable DestinationUrl property.*
    • Image and sound is rendered on demand (via an HttpHandler*), not saved as a file and audio files support caching (with an encrypted filename)*.
    • Encrypts the querystring (128 bit*) to prevent deciphering by reading the HTML source.
    • Works with existing ASP.NET validation controls as well as StringCompareValidator.
    • Can be used on standalone WebForms as well as UserControls.
    • Supports Community Server 2007* and .Text Blogging Engine to prevent spam on blogs.
    • Tested in IE6 & IE7 (PC), IE5 (Mac), FireFox 2 (PC & Mac), Safari 2 (Mac), Safari 3 (PC), Opera 9 (PC)*
    • Full, rich, Visual Studio .NET designer integration, including rendering whilst in design mode and menu options to automatically add configuration settings to the web.config file.
    • Works in a 'ViewState Disabled' environment. 
    • Compatible with Medium Trust environments*.

    * New in Version 2.

    Simple Online Demo (also see the comments section below)



    Design Time:

    Properties Screenshot 1 | 2 | 3

    Visual Studio .NET Design Time Notes:

    1. To get the image to appear when you first drag 'n' drop FormShield to your page, right click on the control and select both 'Add Secret Key' and 'Add HttpHandler', then save the file and right click on a blank space on the page and click 'Refresh'. If that doesn't work, hit the page in a Web browser and repeat the refresh process. You may also need to open, save and close the web.config file.

    2. On occasion the image doesn't reflect property changes made within the property grid. This seems to be either an issue with Visual Studio, or caching. The easiest way to solve the problem (if it happens in the first place) is to save the file and to repeat the refresh process described above. If you are changing image design properties you can also try placing your mouse cursor into the relevant dropdown list and use the cursor keys to navigate through the options.


    Simply download, add to your toolbox, drag 'n' drop to your page and set the relevant properties using the property grid.

    To combine with a validation control (e.g. StringCompareValidator), add the validation control as well as a TextBox to your page, set the StringCompareValidator's 'ControlToCompare' property to point to the FormShield control and the 'ControlToValidate' property to point to the TextBox control. You will also need to set 'EnableClientScript' to False on the validator if 'EncryptQueryString' is set to True on the FormShield control.

    To change the HttpHandler name/path, update your web.config file and change the HttpHandlerPath property value to point to the new handler.

    To specify your own secret key for encryption, add/change the 'formShield_SecretKey' AppSetting in the web.config file.

    Licensing & Download:

    FormShield v2 is released as 'Donationware', for more information, please click here.

    However - You don't have to donate unless you want to - FormShield can still be used for free for both personal and commercial use, however it will periodically (about 10% of the time) render '' as the image text and will play 'This control is provided by' before the text value when someone clicks on the sound icon (again, about 10% of the time).

    If you do decide to donate (thank you!), you will be e-mailed a license key as soon as possible with instructions on how to add it to FormShield so that it removes the '' adverts.

    Whether you have donated or not, you may also redistribute the control royalty free, providing that you don't charge for it. Also, if you intend to distribute the control as part of an application which is publicly available it would be nice to know, although this isn't a requirement.

    Got a good image design? Drop me a line using the contact link and I'll look to include it as a preset. 

    To download, please visit the 'Downloads' area.


    Help & Support:

    Please post in the forum.


    Revision History: 

    Updated 17/07/2007 (v2.0.1):

    • AddUpperLower property added to enable/disable the adding of 'Uppercase' or 'Lowercase' before each character when the sound is played.
    • MultiView design-time issue ('control collection cannot be modified during databind...') - Fixed.

    To use this version you will also need to download v1.0.1 of the Sound Libraries.

    Updated 13/07/2007 (v2.0.0):

    Click here for the changes in this version. 

    For the previous .NET 1.1 version, please click here.

  • FormShield v2.0 & Community Server 2007

    If you check out the comments section today you're bound to have a nice surprise!

    Ok, to the point - FormShield v2 has been added to my Community Server 2007 installation and is working a treat.

  • FormShield v2.0 FINAL Built

    Just a quick post to let everyone know that the release version of FormShield v2.0 is now built.

    I was intending to release it yesterday, but two things happened - 1. I found a small issue whilst testing and 2. I was persuaded to go and see Die Hard 4.0! (Sorry!)

    Just got to finish off a simple demo, zip it all up and create some content and it will be here!

    Posted Jul 12 2007, 02:26 PM by dotNetFreak
    Filed under:
  • Shared Variables - Object Reference Not Set to an Instance of an Object

    Can someone please explain why this throws an exception?

    What's even stranger, is that in one class where I do something similar to this four times, three work fine, but the other one throws an exception...

    Partial Class Strangeness

    Inherits System.Web.UI.Page

    Private _alphaCharacters() As String = MyDefaults.AlphaCharacters

    Public ReadOnly Property AlphaCharacters() As String()


    Return _alphaCharacters

    End Get

    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    End Class

    Class MyDefaults

    Public Shared ReadOnly AlphaCharacters() As String = MyDefaults.DefaultAlphaCharacters
    Public Shared ReadOnly DefaultAlphaCharacters() As String = {"A", "B"}

    End Class

  • StringCompareValidator v2.0.2 Released

    StringCompareValidator v2.0.2 has been released. Click here for details.

  • CasedTextBox v2.0.2 Released

    CasedTextBox v2.0.2 has been released. Click here for details.

  • Migration Complete

    The migration from .Text to CS 2007 is finally complete!

    All content, comments, trackbacks etc. have been imported and I've also restructured my blog, so if you subscribe via RSS, you might need to update your client. Although, to be fair if that's the case, you won't see this until you actually visit the site...

    If you're looking to move your own blog, or to start a new one, then do check out It's a fantastic product with a lot of scope and capabilities.

    Also, if you're moving from .Text, head over to where you'll find the migration utility I used.

    One thing to note if you're migrating from .Text. If, like me you only have a single blog on your Web site, you *might* find an issue when trying to export your existing data using Kevin's software. If no file is created when walking through the wizard, take a look at your .Text 'blog_config' table and see if 'BlogGroup' is set to 'NULL', if so, try changing it to '0' (zero) and see if that helps.

  • A Few Changes...

    As some of you will have noticed I've moved to Community Server 2007 from .Text for my blog!

    I'm still currently porting content and files etc. which is why the release of FormShield v2 has been delayed.

    I'm almost there so I reckon everything will be up and running during the course of tommorrow!

Copyright ©2004-2007 Kevin Gearing. All Rights Reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems