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 (26)

+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 # Dissertation help United Kingdom on 7/17/2010 1:12:45 AM

Dissertation help

Excellent Blog! I really admire your thinking and the way you have put these information in this post. Thanks for sharing an informative post.

Reply

+0 Vote Up     Vote Down # rashid United States on 7/21/2010 10:55:09 AM

rashid

asdf

Reply

+0 Vote Up     Vote Down # buy beats United States on 7/22/2010 9:24:30 AM

buy beats

i will put it on my site.

Reply

+0 Vote Up     Vote Down # Casino Blackjack United States on 7/23/2010 5:58:42 AM

Casino Blackjack

Licensing issues for open source software still persists. In addition to proliferation of licenses, certain licenses are incompatible. There is a dangerous flirtation with the commercial world. Could it be that the open source movement is losing sight of its ideals and philosophy. If they don't know where they are heading, they should remember where they have come from.

Reply

+0 Vote Up     Vote Down # Invest in Austria United States on 7/27/2010 2:39:00 AM

Invest in Austria

Although it is important to keep records for tax purposes,
it is not the only reason (or even the primary reason) good
accounting records should be kept. Another frequent reason
clients request financial statement preparation is to obtain
bank financing. Although important, this also is not the
primary purpose of keeping good records for your business.

Reply

+0 Vote Up     Vote Down # Custom Remodelers United States on 7/27/2010 4:25:35 AM

Custom Remodelers

Customer satisfaction, a business term, is a measure of how products and services supplied by a company meet or surpass customer expectation. It is seen as a key performance indicator within business and is part of the four of a Balanced Scorecard...
http://www.customremodelersminnesota.com/

Reply

+0 Vote Up     Vote Down # casino online Israel on 7/28/2010 9:54:24 AM

casino online

Thanks for sharing those insights with us

Reply

+0 Vote Up     Vote Down # profitability analysis report United States on 7/29/2010 3:36:43 AM

profitability analysis report

This is a very helpful post, i hope this really helps me to complete my project.

Reply

+0 Vote Up     Vote Down # electronic cigarette United States on 7/30/2010 3:59:44 AM

electronic cigarette

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post
Hey everyone, Ive been searching the net the past week and finally found a site that is going to stream every match (all 64 of them) of the Fifa Worldcup 2010 which starts next week.This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.

Reply

+0 Vote Up     Vote Down # zodiac traits United States on 7/31/2010 2:48:02 AM

zodiac traits

Awesome publish.

Reply

+0 Vote Up     Vote Down # magic tickets United States on 7/31/2010 4:32:35 AM

magic tickets

nice article. thanks for your share.

Reply

+0 Vote Up     Vote Down # redwings tickets United States on 7/31/2010 4:33:05 AM

redwings tickets

Excellent Blog! I really admire your thinking and the way you have put these information in this post. Thanks for sharing an informative post.

Reply

+0 Vote Up     Vote Down # redwings tickets United States on 7/31/2010 4:34:33 AM

redwings tickets

very informative. thanks.

Reply

+0 Vote Up     Vote Down # cigarettes Turkmenistan on 7/31/2010 10:37:48 PM

cigarettes

I love this blog

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