Disqus and reCaptcha integration

Topics: ASP.NET 2.0
Coordinator
Apr 4, 2010 at 2:25 AM

Latest source (1.6.0.5) has Disqus and reCaptcha integrated. Here quick instructions on how to enable, if you want try it out before it pushed to download page. Please let us know if you find bugs or have suggestions.

Apr 5, 2010 at 11:46 PM

I d/led the latest source, compiled it under VS2008 and successfully (as best I can tell) upgraded my website from 1.6 to 1.6.0.5 with one exception, the reCaptcha control won't show up on the comment form. I've enabled the captcha and have tried it with show captcha for authenticated users on and off (testing in a different browser window that wasn't logged in). I've got my private and public keys as provided by reCaptcha and the call to reCaptcha appears in the comment control source, it just never shows up on the live page.

Any thoughts on what I've missed? 

Coordinator
Apr 6, 2010 at 8:01 AM

I haven't yet signed up for a Recaptcha account, but I heard they have a 'domain name' setting that you can enforce which requires the domain name in  the URL to match the domain name registered for your Recaptcha account.  And then I think they have a setting to allow any domain name to use your API keys.  If you're testing on your local machine, the domain name might not match what you have registered.

Apr 6, 2010 at 10:23 PM

I believe that using "localhost" or "127..." both work, even if the domain that was registered for reCaptcha is not a global one.  In any case, the domain is used during validation, so that shouldn't prevent the reCaptcha from appearing (at least haven't seen that to be the case).

Are you using the XML provider, or the DB provider? I've seen someone post that there may be an issue with the DB setting provider, since there is a difference in the type of object that is returned (stream vs string) in the providers. I haven't had a chance to look into this yet, but it could be causing an issue. I've just been crazy busy the last few weeks....

Apr 7, 2010 at 4:00 AM
mjg wrote:

I d/led the latest source, compiled it under VS2008 and successfully (as best I can tell) upgraded my website from 1.6 to 1.6.0.5 with one exception, the reCaptcha control won't show up on the comment form. I've enabled the captcha and have tried it with show captcha for authenticated users on and off (testing in a different browser window that wasn't logged in). I've got my private and public keys as provided by reCaptcha and the call to reCaptcha appears in the comment control source, it just never shows up on the live page.

Any thoughts on what I've missed? 

Just as an aside to those who might suffer a similar problem. When you install this version the reCaptcha extension is DISABLED by default. You need to ENABLE it to turn it on. Imagine my embarrasement when rtur pointed out my stupidity to me in his blog comments.

Thank you fstanek for contributing this to the community and letting them add it into the build GREAT stuff!

MJG

Apr 23, 2010 at 7:10 PM

Hi guys! I just upgraded from 1.6.0 to 1.6.1, following the "lazy" update steps described here (replacing individual files) http://www.dotnetblogengine.net/post/BlogEngine-161-Update.aspx (btw I use MS SQL as back end).
For some reason I can't get ReCaptcha to work on my website (www.clear-lines.com/blog): I got the key, enabled it, and the control shows up on the comments section, but a few things are not working right:

1) when I submit a comment, I see the ReCaptcha, but I get the following message: 

"Sorry, the following error occurred while processing your comment: There was an error in the callback."

... and the comment gets in queue anyways, regardless of whether the right words have been typed or not in the ReCaptcha control.

2) Furthermore, when I enable/disable the extension the following message shows up:

"Changes will not be applied: Access to the path 'd:\hosting\clearlines\blog\Web.Config' is denied." - and when I look at View source for the ReCaptcha, I get the following:

"Source for [d:\hosting\clearlines\blog\App_Code\Extensions\Recaptcha.cs] not found"

Which indicates some mismatch I think, because Recaptcha.cs is in a folder one level deeper, in Extensions\Recaptcha\

Do you guys have any suggestion on what I did wrong? Any help would be appreciated!

Thanks in advance,

Mathias

Coordinator
Apr 23, 2010 at 7:45 PM

#2 is not an issue, if you have web.config as read only you'll get that error because BE is trying to recycle application by changing timestamp on web.config. You can do it manually if you have access to IIS or your host gives you another way of doing it. Also try to delete temp internet files in the browser or open your site in another browser to make sure java script is reloaded.

Apr 25, 2010 at 8:11 AM

rtur, thanks for the input. It seems to be partially working:

1. when an incorrect ReCaptcha combination is entered, the comment isn't queued,

2. when a correct ReCaptcha is entered, the comment is queued - but there is a pop-up "Sorry, the following error occurred while processing your comment: There was an error in the callback."

Any idea where the problem could be coming from?

Apr 27, 2010 at 7:59 AM

Hi,
I have see the same problem on my blog, and the problem is about a cast of string to Stream.
I have change the cast  in the function BlogService.LoadFromDataStore, that in my case return a string and not a stream.

In the method BindGrid that is in the page RecaptchaLogViewer.aspx, now I have change in:

string s = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (!string.IsNullOrEmpty(s))
{
    using (StringReader reader = new StringReader(s))
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
        log = (List<RecaptchaLogItem>)serializer.Deserialize(reader);
    }
}
...

and the same code are changed in the UpdateLog method that is in RecaptchaControl class.

I don't know the reason about only me have this problem... I use blogengione with sql server... and not have other differences in the code.

Apr 27, 2010 at 9:13 PM
Hi Andrea, Thanks so much for your fix, it did resolve my problem. Grazie Mille! Mathias
May 3, 2010 at 8:51 PM

Well spotted Andrea, this sorted my issue as well. I'm also using a SQL Server backend.

May 6, 2010 at 2:03 AM

Here's a noob question, hope you can help me.

Ok, I found those files:  RecaptchaLogViewer.aspx.cs, RecaptchaLogViewer.aspx, and RecaptchaControl.cs. I found the code and changed it, no problem.

 

However,  RecaptchaControl.cs had all this

     Stream s = (Stream)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
                List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
                if (s != null)
                {
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
                    log = (List<RecaptchaLogItem>)serializer.Deserialize(s);
                    s.Close();
                }
    
   
                log.Add(logItem);

                if (log.Count > MaxLogEntries)
                {
                    log.RemoveRange(0, log.Count - MaxLogEntries);
                }

                BlogService.SaveToDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog", log);

                RecaptchaAttempts = 0;
                PageLoadTime = DateTime.Now;
                HttpContext.Current.Cache.Remove(UserUniqueIdentifier + "RecaptchaChallengeValue");
                HttpContext.Current.Cache.Remove(UserUniqueIdentifier + "RecaptchaResponseValue");

            }
        }

Where does the altered code go? thanks in advance

May 6, 2010 at 7:14 AM

You can find the same code in the file RecaptchaLogViewer.aspx.cs in the BindGrid method.

You must replace this code:
         Stream s = (Stream)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
         List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
         if (s != null)
         {
               System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
               log = (List<RecaptchaLogItem>)serializer.Deserialize(s);
               s.Close();
         }

with this:
       string s = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
       List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
       if (!string.IsNullOrEmpty(s))
       {
           using (StringReader reader = new StringReader(s))
           {
               System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
               log = (List<RecaptchaLogItem>)serializer.Deserialize(reader);
           }
       }

May 6, 2010 at 3:41 PM

Thank you

Jun 11, 2010 at 8:42 AM
rtur wrote:

Latest source (1.6.0.5) has Disqus and reCaptcha integrated. Here quick instructions on how to enable, if you want try it out before it pushed to download page. Please let us know if you find bugs or have suggestions.

 I updated my BlogEngine installation to 1.6.1 which seems to incorporate reCaptcha as an extension.  But it doesn't show up at all.

I have enabled it, of course.  I registered for a key and entered that info.  Made the key global thinking I might use it for other domains. 

When managing extensions, if I click on view, I see the same thing mathiasb does: 

Source for [...my host's directory setup .,,, \App_Code\Extensions\Recaptcha.cs] not found  and as mathiasb writes, Recaptcha.cs in this version of BlogEngine is in its own subdir of Extensions.  What gives?

I don't know what to do.  Would like to use BlogEngine and have gotten others to try it out as well, but we are all hit by spambots.  Some have given up on comments altogether.  Really not acceptable.

I am using an MS SQL db rather than xml.  But from what I read here, that issue comes up further on, and doesn't explain why recaptcha is not present on my pages.  (have deleted temp internet files, reloaded - checked to see my file structure matches the 1.6.1. download package - deleted the extension mgr dir as instructed )  It seems there should be nothing more to do.  Can anyone help?

 

Coordinator
Jun 12, 2010 at 3:22 AM
chickcove wrote:
I am using an MS SQL db rather than xml.  But from what I read here, that issue comes up further on, and doesn't explain why recaptcha is not present on my pages.  (have deleted temp internet files, reloaded - checked to see my file structure matches the 1.6.1. download package - deleted the extension mgr dir as instructed )  It seems there should be nothing more to do.  Can anyone help?

 

There is a page on enabling recaptcha in documentation section: http://blogengine.codeplex.com/wikipage?title=EnablingRecaptcha&referringTitle=Documentation

The "not found" warning is ok, it shows up because extension is not in standard location and source code is not available for editing online.

There is an issue with recaptcha logging with SQL provider that has been fixed since 1.6.1, so you might disable recaptcha logging in settings and see if this will help, just in case.

Jun 12, 2010 at 5:33 AM

Thanks, rtur, but still no go.  I reviewed the instructions, and went and disabled the recaptcha extension while fetching a new set of keys.  entered them and disabled logging and then re-enabled the extension.  have logged out, have deleted temp files, closed all browsers and restarted.  Never a recaptcha image to be seen.  But all the extensions were listed twice in extension mgr!  So I opened ftp and went back to the BE 1.6.1 download, deleted extension folders from the server and re-upped.  Now I'm back to a single list of extensions.  Keys still present.  Settings OK.  NO RECAPTCHA image.  I really wanted to catch up with this tonight and be done with it.  It is just turning into an enormous waste of time. 

Yet this morning, I helped someone else get it straight - had put a friend's site on my reseller hosting, had uploaded BE - 1.6.1 from the start, not an upgrade like mine - and we got her recaptcha to work.  I just picked up keys for her and it all went as easily as the instructions say.    Some odd things about comments being closed when they weren't, and then finally OK except latest entry had no recaptcha on its comment form, so I suggested she delete that blog entry and re-create it.

I'd actually had a little more trouble with her original installation than with mine, since hers went into a subdir of an existing site, and I started mine in the root of a new domain.

Only other diffs are her data store being xml and mine being ms sql.    I don't HAVE to use a db of course, it's just I use ms sql on all my sites (all are .net), and for some domains, including this one, I use common encryption keys and so can combine membership when/where I want. 

Have exported to xml file tonight and am considering deleting and re-installing completely.  Would be the 2nd time ... 

Any other ideas of what's wrong?

Sep 11, 2010 at 10:31 PM

This worked for me.. (I was getting an alert popup message box when I entered in an incorrect captcha)

thanks

 

You must replace this code:
         Stream s = (Stream)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
         List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
         if (s != null)
         {
               System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
               log = (List<RecaptchaLogItem>)serializer.Deserialize(s);
               s.Close();
         }

with this:
       string s = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
       List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
       if (!string.IsNullOrEmpty(s))
       {
           using (StringReader reader = new StringReader(s))
           {
               System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
               log = (List<RecaptchaLogItem>)serializer.Deserialize(reader);
           }
       }

 

Oct 28, 2010 at 10:17 PM

 

andreadottor solution "

Hi,
I have see the same problem on my blog, and the problem is about a cast of string to Stream.
I have change the cast  in the function BlogService.LoadFromDataStore, that in my case return a string and not a stream.

In the method BindGrid that is in the page RecaptchaLogViewer.aspx, now I have change in:

string s = (string)BlogService.LoadFromDataStore(BlogEngine.Core.DataStore.ExtensionType.Extension, "RecaptchaLog");
List<RecaptchaLogItem> log = new List<RecaptchaLogItem>();
if (!string.IsNullOrEmpty(s))
{
    using (StringReader reader = new StringReader(s))
    {
        System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List<RecaptchaLogItem>));
        log = (List<RecaptchaLogItem>)serializer.Deserialize(reader);
    }
}
...

and the same code are changed in the UpdateLog method that is in RecaptchaControl class.

I don't know the reason about only me have this problem... I use blogengione with sql server... and not have other differences in the code.

"
 worked with me, you have 2 change the code in both files
Oct 29, 2010 at 7:16 PM

The logging piece really should be removed from the recaptcha.  It isn't really useful for anything (I used it for testing purposes, but I'm guessing most people aren't interested in that).  

There is a separate issue in that the LoadFromDataStore method should not have a different signature based on the provider, but I'm not sure if that can be fixed easily without affecting lots of other stuff.

Nov 1, 2010 at 3:21 PM

Just ignore my last comment.  I see you guys rewrote the whole thing already in the newest version ;)

BTW, latest build of BE.NET looks great.