Async Recaptcha for BlogEngine.NET 1.6

by Filip Stanek 20. February 2010 05:03

UPDATE: The latest installation instructions and files are available by following this link: http://www.bloodforge.com/post/BlogengineNET-reCaptcha-093-Installation-Instructions.aspx

The instructions on this page are no longer valid for the latest version.

I really am getting sick of the spam that is appearing on this blog, so yesterday I decided to implement Recaptcha for BlogEngine.NET. I had three main goals:

  1. Easy to implement – as any control, it needs to be pretty trivial to add it to an existing blog instance
  2. Configurable via the Extensions panel – I really like what BlogEngine has done with their ability to edit extensions, so I wanted the control to be configurable in this way
  3. It had to be asynchronous – when a user posts a comment, I don’t want the whole page to refresh

The final solution is pretty close to what I had in mind.  The extension is a single file that needs to be inserted into the ‘/App_Code/Controls’ folder.  In addition, two lines of code need to be added/modified in the ‘/User controls/CommentView.ascx’ file.

Just a quick note to anyone who may want to implement this on your own.  I have noticed that once in a while, when using IE, I get an error that BlogEngine is not defined and the error points to the following file: ‘/js.axd?path=%2fadmin%2fwidget.js&v=1.6.0.1’. The changes involved shouldn’t have any effect on this, but I am not 100% sure if this is due to my code or not. If it is, hopefully I’ll figure it out in the next day or so, as I’m way to tired right now. [ this should now be fixed in the 0.95 version ]

To implement the Recaptcha control, the following steps need to be taken:

  1. Download Recaptcha.zip, extract the file in it, and place the file in the /App_Code/Controls folder.
  2. Open ‘/User controls/CommentView.ascx’ in the editor of your choice and put in the following line at the spot where you would like your control to appear.  On this blog, the code is right above the submit button when posting comments.

    <blog:RecaptchaControl ID="recaptcha" runat="server" TabIndex="8" /><br />

    In the example above, I also put in an extra line break for some extra white space.  I have also put in a TabIndex ( and changed the TabIndex of the submit button ).
  3. The onClick event on the actual submit button needs to change. If you have not modified the code at all, the submit button should look like this:

    <input type="button" id="btnSaveAjax" value="<%=Resources.labels.saveComment %>" onclick="return BlogEngine.validateAndSubmitCommentForm()" tabindex="7" />

    For the recaptcha code to work, the submit button needs to change to the following:

    <input type="button" id="btnSaveAjax" value="<%=Resources.labels.saveComment %>" onclick="return validateWithRecaptcha()" tabindex="9" />

That’s it.  No recompile is needed, and the Recaptcha control should be functional.  If you go to your extensions section, you’ll notice that the Recaptcha control is there and available for editing.  You can ( and probably should ) create your own account on Recaptcha.netand put in a Public and Private key that corresponds to your site. The keys in there are for my site, but they are “global” keys which should work from any domain. You can also disable the control altogether, change it so it does not appear for logged in users, and change the theme.

The control also allows you to create a custom theme.  To do so, you need to specify the name of the theme directly in the tag in the CommentView.ascx file mentioned above. So, for example:

<blog:RecaptchaControl ID="recaptcha" runat="server" TabIndex="8" Theme=”MyCustomTheme” />

You’ll find the rest of the info about what you need to do to skin the Recaptcha on their site.

As always, let me know if you’d like to see anything added to the control, or if you experience any bugs with it.  I’ll be looking into the bug mentioned above this weekend to determine if the control is actually causing this issue mentioned above.  I have a feeling I know how to fix it even if it isn’t, but I’ll just have to run some tests…

Tags: , , , , , ,

Web Development

Comments

  • Comments (37)

+0 Vote Up     Vote Down # The Lunatic United States on 2/20/2010 7:05:33 AM

The Lunatic

Thanks Filip - I got to your page via the blog engine forum.  I will try this solution asap, as I am getting killed by all the spam comments.

Reply

+0 Vote Up     Vote Down # Filip United States on 2/21/2010 12:19:15 AM

Filip

Cool, I hope it works as expected!

Also, I made an update the the code above, since the 0.90 version linked to in this post has a potential vulnerability - it is possible to add a comment w/o passing the Recaptcha check by manually executing JavaScript on the page.  The latest version should resolve this issue.  However, this comes at a price, since it is now a little more difficult to integrate the control in the page.

If you do decide on upgrading to the latest version, keep in mind that you will need to restore the javascript being called in the submit button to the original javascript call.

The latest installation instructions are available at: www.bloodforge.com/.../...lation-Instructions.aspx

Reply

+0 Vote Up     Vote Down # Abe United States on 3/1/2010 11:44:59 PM

Abe

Test Comment! Hope this works.  I've been having a hell of a time getting reCAPTCHA integrated with my BE.NET

Reply

+0 Vote Up     Vote Down # Web Timesheet Blog United States on 3/6/2010 10:43:17 AM

Web Timesheet Blog

testing to see if it works before putting in my site.

Reply

+0 Vote Up     Vote Down # psivarad United States on 5/25/2010 5:11:49 PM

psivarad

Thanks Filip.  Testing to see if it works before putting in my site.

Reply

+0 Vote Up     Vote Down # Sam United Kingdom on 6/23/2010 3:45:13 AM

Sam

I've found this is the best way to prevent SPAM, my SPAM fell by about 60%! I still get some but it's far more manageable

Reply

+0 Vote Up     Vote Down # mafia game online United States on 8/27/2010 10:09:36 PM

mafia game online

Mafia style games rule, theres a ton online anymore to play too! its great.

Reply

+0 Vote Up     Vote Down # investment in manchester United States on 8/31/2010 2:43:37 AM

investment in manchester

Well i must say that selling online is not that easy it require a lot of time to get the site recognize. Thanks for the tips man

Reply

+0 Vote Up     Vote Down # crm software in United States on 8/31/2010 3:50:50 AM

crm software in

I wanted to thank you for this great read. Your blog is one of the finest blog . Thanks for posting this informative article.

Reply

+0 Vote Up     Vote Down # sarasota real estate United States on 8/31/2010 10:17:41 AM

sarasota real estate

I used this on my real estate blog with great success.

Reply

+0 Vote Up     Vote Down # Structured Insurance Settlement United States on 8/31/2010 5:34:01 PM

Structured Insurance Settlement

selling online is so hard , need more dedication !!

Reply

+0 Vote Up     Vote Down # Joye 510 starter kit United States on 9/1/2010 1:47:13 PM

Joye 510 starter kit

With any thing in life you have to work hard to reap the rewards.  Selling online is not guaranteed money!

Reply

+0 Vote Up     Vote Down # panic away scam review United States on 9/2/2010 4:17:43 AM

panic away scam review

Too much valuable things are shared here,I really appreciated form above information ,In past I was searching like that,now I caught all the inforamtion which I want,So thanks for sharing
pretty good post.

Reply

+0 Vote Up     Vote Down # how to stop hair loss, how to stop hair fall, prevent hair loss, prevent hair fall United States on 9/2/2010 4:18:49 AM

how to stop hair loss, how to stop hair fall, prevent hair loss, prevent hair fall

Only want to say your article is brilliant. The clearness in your post is simply spectacular and i can assume you are an expert on this subject. Well with your permission allow me to grab your rss feed to keep up to date with succeeding post. Thanks a million and please keep up the effective work.

Reply

+0 Vote Up     Vote Down # russian translation United States on 9/3/2010 8:31:26 AM

russian translation

Are you looking for quality business translation for business in Russia? BBRussian.com is specializing in Russian translation including business, legal, technical, and medical translations

Reply

+0 Vote Up     Vote Down # classic loafer United States on 9/3/2010 3:43:32 PM

classic loafer

Ive beeen doing alot of research on blogengine, seems like its spammy...I think im gonna stick with wordpress for now. nice page...thx

Reply

+0 Vote Up     Vote Down # seeking women India on 9/4/2010 2:34:52 AM

seeking women

I wanted to thank you for this great read. Your blog is one of the finest blog . Thanks for posting this informative article.

Reply

+0 Vote Up     Vote Down # dog grooming help for dummies Singapore on 9/4/2010 2:48:33 AM

dog grooming help for dummies

Recaptcha is a good option. I hope I can also install this in my blog.Thanx for sharing.

Reply

+0 Vote Up     Vote Down # online crm United States on 9/4/2010 12:19:37 PM

online crm

(AIM) AOL Instant Messenger popularity remains intact, even with the advent of Web 2.0 social media applications. AOL parent company keeps updating its free instant messaging program with new features .....

Reply

+0 Vote Up     Vote Down # mesothelioma attorney United States on 9/5/2010 8:16:36 AM

mesothelioma attorney

I used to read so many articles those were really not touching, this one was simply superb,keep posting like this...

Reply

+0 Vote Up     Vote Down # overstock coupon code United States on 9/6/2010 1:21:50 AM

overstock coupon code

Simply, the blog post is in fact the best on this valuable theme. I agree with your decisions and will thirstily look forward to study your approaching updates. Just saying thanks will not just be sufficient, to the phenomenal clarity within your writing. I will directly grab your feeds to stay informed of any updates. Fabulous perform and significantly success in your company enterprise! Have a nice day

Reply

+0 Vote Up     Vote Down # custom web design United States on 9/6/2010 2:45:42 AM

custom web design

I have 1.4.5.15 installed, persisting to App_Data. If I back up the data directory, delete everything, apply this version, and copy App_Data, will it work (at least with minor tuning)?

Reply

+0 Vote Up     Vote Down # Chicago condos United States on 9/6/2010 2:48:26 AM

Chicago condos

It looks like you should be fine, app_data folder structure did not change between 1.4.5 and 1.6. Surely backup is must and testing locally first would be good idea, some minor tweaks might be needed, but nothing major.

Reply

+0 Vote Up     Vote Down # Chicago condos United States on 9/6/2010 2:51:47 AM

Chicago condos

Cool enhancements and handy bugfixes! Like it and hope comment spam now is reduced by adding reCaptcha

Reply

+0 Vote Up     Vote Down # Chicago condos United States on 9/6/2010 2:53:23 AM

Chicago condos

Nice discussion going around here thanks for sharing this with us

Reply

+0 Vote Up     Vote Down # american gold coin prices United States on 9/6/2010 10:25:18 AM

american gold coin prices

I loved the post written by you... very useful and thanks for sharing the information... Will be revisiting your blogs for further updates. Thanks

Reply

+0 Vote Up     Vote Down # overstock coupon code United States on 9/6/2010 10:40:50 AM

overstock coupon code

Effortlessly, the website post is in fact the very best on this valuable theme. I agree with your decisions and will thirstily look forward to read your approaching updates. Just saying thanks will not just be sufficient, for your phenomenal clarity inside your writing. I will directly grab your feeds to stay informed of any updates. Fabulous operate and significantly success with your business enterprise! Have a nice day

Reply

+0 Vote Up     Vote Down # eiknujomorp United States on 9/6/2010 8:44:15 PM

eiknujomorp

when i saw the process of blogengine.net it is really good easy and easy to index .

Reply

+0 Vote Up     Vote Down # WebSite Design Company Australia on 9/7/2010 7:28:53 AM

WebSite Design Company

You have got some great posts in your blog. Keep up with the good work.

Reply

+0 Vote Up     Vote Down # translation to russian United States on 9/7/2010 10:51:46 AM

translation to russian

Not sure if this applies to your case, but you may consider using Russian translation. Russia is one of the largest markets in the world and their economy is rock-solid despite the recession

Reply

+0 Vote Up     Vote Down # Keith Hungary on 9/7/2010 11:58:39 AM

Keith

Everything on this blog is so true! In addition you've created an brilliant article once again! Your style of writing on this site is perfect, I really enjoy the blog posts. I check your website regularly and enjoy the fact its popular and has regular users
Wonderful site thanks a lot for sharing

Reply

+0 Vote Up     Vote Down # Anti Aging Eye Cream Principality of Monaco on 9/7/2010 2:29:48 PM

Anti Aging Eye Cream

It's really important to be serious when it comes to skin care. Using some non-branded products can cause severe damage to your skin.  I will follow your blog for some more helpful tips about skin care.

Reply

+0 Vote Up     Vote Down # ffxiv gil People's Republic of China on 9/8/2010 1:16:11 AM

ffxiv gil

i believe brand products,must be careful.

Reply

+0 Vote Up     Vote Down # crm online solution United States on 9/8/2010 1:20:49 PM

crm online solution

ASP.NET is a free technology offered by Microsoft. It allows webmasters and programmers to easily create Web applications that are dynamic and elegant.

Reply

+0 Vote Up     Vote Down # Seattle DUI Attorney United States on 9/9/2010 3:48:04 AM

Seattle DUI Attorney

I would very much like to agree with the previous commenter! I find this blog really useful for my uni project. I hope to add more useful posts later.

Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading




Tag cloud

About Filip Stanek

Death Note Pic I'm a developer at ACG Multimedia in Cincinnati, OH. Besides working with ASP.NET, Flash, and other web technologies, I enjoy playing chess, video games, etc.

Currently playing:
- Final Fantasy XIII
E-mail me Send mail

Recent Comments

Comment RSS

Month List

Page List