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.
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:
- Download the External Templates Zip from Sitefinity Downloads
- Unzip the External Templates to a temporary directory
- Copy: [zip]/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx
To: [website]/Custom/ControlTemplates/Blogs/ContentViewSingleItem.ascx - 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.
3. Click the Appearance section
4. Type ~/Custom/ControlTemplates/Blogs/ContentViewSingleItem.ascx for the SingleItemTemplatePath
5. Click I'm done and then save the page
CAPTCHA will now be enabled for Sitefinity blog comments.