{"id":57,"date":"2010-02-20T00:00:00","date_gmt":"2010-02-20T00:00:00","guid":{"rendered":"http:\/\/bloodforge.com\/?p=57"},"modified":"2020-02-20T02:24:33","modified_gmt":"2020-02-20T02:24:33","slug":"async-recaptcha-for-blogengine-net-1-6","status":"publish","type":"post","link":"https:\/\/bloodforge.azurewebsites.net\/index.php\/2010\/02\/20\/async-recaptcha-for-blogengine-net-1-6\/","title":{"rendered":"Async Recaptcha for BlogEngine.NET 1.6"},"content":{"rendered":"\n<p><strong>The instructions on this page are no longer valid for the latest version.<\/strong><\/p>\n\n\n\n<p>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:<\/p>\n\n\n\n<ol><li>Easy to implement \u2013 as any control, it needs to be pretty trivial to add it to an existing blog instance<\/li><li>Configurable via the Extensions panel \u2013 I really like what BlogEngine has done with their ability to edit extensions, so I wanted the control to be configurable in this way<\/li><li>It had to be asynchronous \u2013 when a user posts a comment, I don\u2019t want the whole page to refresh<\/li><\/ol>\n\n\n\n<p>The final solution is pretty close to what I had in mind.&nbsp; The extension is a single file that needs to be inserted into the \u2018\/App_Code\/Controls\u2019 folder.&nbsp; In addition, two lines of code need to be added\/modified in the \u2018\/User controls\/CommentView.ascx\u2019 file.<\/p>\n\n\n\n<p><s>Just a quick note to anyone who may want to implement this on your own.&nbsp; 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: \u2018\/js.axd?path=%2fadmin%2fwidget.js&amp;v=1.6.0.1\u2019. The changes involved shouldn\u2019t 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\u2019ll figure it out in the next day or so, as I\u2019m way to tired right now.<\/s>&nbsp;[ this should now be fixed in the 0.95 version ]<\/p>\n\n\n\n<p>To implement the Recaptcha control, the following steps need to be taken:<\/p>\n\n\n\n<ol><li>Download\u00a0Recaptcha.zip, extract the file in it, and place the file in the \/App_Code\/Controls folder.<\/li><li>Open \u2018\/User controls\/CommentView.ascx\u2019 in the editor of your choice and put in the following line at the spot where you would like your control to appear.\u00a0 On this blog, the code is right above the submit button when posting comments.\u00a0<br><code>&lt;blog:RecaptchaControl ID=\"recaptcha\" runat=\"server\" TabIndex=\"8\" \/>&lt;br \/>\u00a0<\/code><br>In the example above, I also put in an extra line break for some extra white space.\u00a0 I have also put in a TabIndex ( and changed the TabIndex of the submit button ).<\/li><li>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:\u00a0<br><code>&lt;input type=\"button\" id=\"btnSaveAjax\" value=\"&lt;%=Resources.labels.saveComment %>\" onclick=\"return BlogEngine.validateAndSubmitCommentForm()\" tabindex=\"7\" \/>\u00a0<\/code><br>For the recaptcha code to work, the submit button needs to change to the following:\u00a0<br><code>&lt;input type=\"button\" id=\"btnSaveAjax\" value=\"&lt;%=Resources.labels.saveComment %>\" onclick=\"return validateWithRecaptcha()\" tabindex=\"9\" \/><\/code><\/li><\/ol>\n\n\n\n<p>That\u2019s it.\u00a0 No recompile is needed, and the Recaptcha control should be functional.\u00a0 If you go to your extensions section, you\u2019ll notice that the Recaptcha control is there and available for editing.\u00a0 You can ( and probably should ) create your own account on\u00a0<a href=\"http:\/\/www.recaptcha.net\/\">Recaptcha.net<\/a> and put in a Public and Private key that corresponds to your site. The keys in there are for my site, but they are \u201cglobal\u201d 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.<\/p>\n\n\n\n<p>The control also allows you to create a custom theme.&nbsp; 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:<\/p>\n\n\n\n<p><code>&lt;blog:RecaptchaControl ID=\"recaptcha\" runat=\"server\" TabIndex=\"8\" Theme=\u201dMyCustomTheme\u201d \/><\/code><\/p>\n\n\n\n<p>You\u2019ll find the rest of the info about what you need to do to skin the Recaptcha on their&nbsp;<a href=\"http:\/\/www.recaptcha.net\/\">site<\/a>.<\/p>\n\n\n\n<p>As always, let me know if you\u2019d like to see anything added to the control, or if you experience any bugs with it.&nbsp; I\u2019ll be looking into the bug mentioned above this weekend to determine if the control is actually causing this issue mentioned above.&nbsp; I have a feeling I know how to fix it even if it isn\u2019t, but I\u2019ll just have to run some tests\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: Easy to implement \u2013 as any control, it needs to be pretty trivial to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/57"}],"collection":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":1,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/57\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bloodforge.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}