Go Back

Enabling CAPTCHA on a Sitefinity Blog

Out of the box, Sitefinity ASP.NET CMS provides several tools to help manage the web site.  One of these tools is the SpamProtector control; this control can be used to prevent SPAM from being posted through public facing forms (blog comments, forums, guestbook, etc).

The SpamProtector control uses several techniques to identify SPAM.  One of these techniques is CAPTCHA.  By default, CAPTCHA is not enabled on Sitefinity blog comments.  Recently, I was forced to enable CAPTCHA for this blog. 

Below are the steps involved in enabling CAPTCHA for Sitefinity blog comments:

Locate the Blog Post SpamProtector Control

It’s very easy to modify many properties for the Sitefinity’s Blog Posts control.  However, the Basic Blog Posts control editor does not include an option to enable CAPTCHA.

Sitefinity BlogPosts Control Basic Options

To get access to the SpamProtector control, the embedded template used by the BlogPosts control needs extracted and modified

Extract the Blog Posts Single Item Template

The embedded control templates used by Sitefinity 3.6 can be downloaded, edited and then used.  Follow the steps below to retrieve & install the embedded template:

  1. Download the External Templates Zip from Sitefinity Downloads
  2. Unzip the External Templates to a temporary directory
  3. Copy:  [zip]/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx
    To: [website]/Custom/ControlTemplates/Blogs/ContentViewSingleItem.ascx
  4. Copy: [zip]/Sitefinity/ControlTemplates/Blogs/App_LocalResources
    To: [website]/Custom/ControlTemplates/Blogs/App_LocalResources

Modify the SpamProtector Tag in the Single Item Template

Open the ~/Custom/ControlTemplates/Blog/ContentViewSingleItem.ascx and find the <SpamProtector> tag.

<sfWeb:SpamProtector id="spamProtector" runat="server" cssclass="commentsValidator hide"
enableautobotdiscovery="true" enablehiddentextboxstrategy="true"
hiddentextboxerrormessage="Hidden TextBox has some text in it!" hiddentextboxlabel="Do not fill this textbox!"
hiddentextboxlabelcssclass="hide" hiddentextboxinputcssclass="hide" enablemintimeoutstrategy="true"
mintimeout="2" mintimeouterrormessage="Submission too fast!" />

CAPTCHA can be enabled using the SpamProtector’s EnableCaptcha property.  In addition to this property, the following properties can be used to configure various CAPTCHA options:

  • EnableCaptcha
  • CaptchaBackgroundNoise
  • CaptchaExpirationMsg
  • CaptchaFontFamilyName
  • CaptchaFontWarp
  • CaptchaImageAltText
  • CaptchaImageCssClass
  • CaptchaImageHeight
  • CaptchaImageWidth
  • CaptchaLayoutTemplatePath
  • CaptchaLength
  • CaptchaLineNoise
  • CaptchaMaxTimeout
  • CaptchaPossibleChars
  • CaptchaTextBoxAccessKey
  • CaptchaTextBoxCssClass
  • CaptchaTextBoxLabel
  • CaptchaTextBoxLabelCssClass
  • CaptchaTextBoxTabIndex

Modify the SpamProtector tag to configure CAPTCHA.  The following example <SpamProtector> tag will enable CAPTCHA for blog comments:

<sfWeb:SpamProtector id="spamProtector" runat="server" cssclass="commentsValidator hide" 
EnableCaptcha="true" CaptchaFontWarp="High" CaptchaBackgroundNoise="High" CaptchaLineNoise="High"
enableautobotdiscovery="true" enablehiddentextboxstrategy="true"
hiddentextboxerrormessage="Hidden TextBox has some text in it!" hiddentextboxlabel="Do not fill this textbox!"
hiddentextboxlabelcssclass="hide" hiddentextboxinputcssclass="hide" enablemintimeoutstrategy="true"
mintimeout="2" mintimeouterrormessage="Submission too fast!" />

Configure the Blog Posts Control to use the new External Template

1.  Edit the BlogPosts control.

2.  Click the Advanced tab.

Sitefinity - Basic Options for the Blog Posts Control

3.  Click the Appearance section

4.  Type ~/Custom/ControlTemplates/Blogs/ContentViewSingleItem.ascx for the SingleItemTemplatePath

Sitefinity Setting an External Template for the Blog Posts Control

5.  Click I'm done and then save the page

CAPTCHA will now be enabled for Sitefinity blog comments.

Comments  1

  • Chad 31 Aug

    Does this only apply to the comments in the blog or can it also apply to the comments in the news and products sections as well?
Post a comment!
  1. Formatting options
       
     
     
     
     
       
  2. I'm sorry for the CAPTCHA. You have spammers to thank for this: