I am having a similar problem, though for mine the page does a post back, and when the page is refreshed there is no indicator that the captcha was incorrect (works fine for correct captchas). I'm guessing this is because Google has moved their API URL for ReCaptcha. See here: https://groups.google.com/d/msg/recaptcha-announce/wf9oREIMnmM/raV_6oNg4kYJ
The reason I am guessing that is because my Fiddler2 capture of the traffic shows this (I replaced some sensitive information and the extraneous markup):
http://api.recaptcha.net/challenge?k={UNIQUE_ID}&error=incorrect-captcha-sol The document has moved <A HREF="http://www.google.com/recaptcha/api/challenge?k={UNIQUE_ID}&error=incorrect-captcha-sol">here</A>.
I tried to update http://www.nuget.org/packages/Microsoft.AspNet.Web.Helpers.Mvc/ (where the ReCaptcha functionality is apparently in), but that broke other functionality (I was getting a runtime error on any page with comments due to some version incompatibility between assemblies).
Actually, I'm thinking I may be mistaken. Maybe uCommentsy just doens't display an error message when the user gets the ReCaptcha wrong? Based on the code in uCommentsyFormContact.cshtml, it looks like there is some code to handle the case where the query string has a parameter of "success" set to "error". However, it does not redirect to that URL on error. Maybe that's intended for errors other than ReCaptcha mistakes?
Making some progress. Looking in the action method (uCommentsyContactFormSurfaceController.Post), the only thing that I can see that might indicate a failed captcha is this line:
if (!ModelState.IsValid) { return CurrentUmbracoPage(); }
That is at the top of the action method. If that's the case, then any captcha failure would just return the current page, without any indication there was an error. I might be able to use that to test for failed comments, supposing there are not other forms on the page that use model state and supposing I can access ModelState from the view itself. Otherwise, this may require that I recompile uCommentsy and alter the behavior of that action method (e.g., to redirect to the error URL when the captcha fails).
Making further progress. I think I was wrong about the above code. This looks like the offending code:
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey]) && !ReCaptcha.Validate(ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey]) && ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey] != "," && ConfigurationManager.AppSettings[Keys.RecaptchaPrivateKey] != ",") { // this allows the developer to simply remove recaptcha and the config setting if they dont want it. return CurrentUmbracoPage(); }
Based on an article I just found (http://www.dotnetcurry.com/showarticle.aspx?ID=611), the ReCaptcha.Validate method is what does the validation. I suppose that method must look at Request.Form for the recaptcha answer (I looked it over before because I only saw the private key being passed as a parameter, but then realized it can access the HttpContext without it being passed as a parameter).
I can probably just do the same thing to test if the captcha response was valid and take some appropriate action (e.g., display message, redirect user).
Baldy it dawned on me that perhaps there could be a dll which was conflicting. This happened to me a long time ago. I cant remember what the fix was, although I think it had somehting to do with webapi :/
Nicholas, this may be a silly question, but I assume you have the recaptcha keys in your web.config?
Yes, I have ReCaptcha keys in my web.config. I eventually got it working by creating a helper method to detect if the captcha solution was valid or not (I then display an error message to the user if their solution was invalid). I consider this to be a workaround and am not aware of there being a built-in method to ascertain whether or not the uCommentsy post was valid or not. Here is my helper method (note that I also render the "uCommentsyReCaptchaSolutionFlag" input field in the form to be sure it was actually the comment form being submitted):
// Namespaces. using Microsoft.Web.Helpers; using System.Configuration; using Umbraco.Core; usinguCommentsyKeys = uCommentsy.BusinessLogic.Constants.Keys;
///<summary> /// Helps with page comments. ///</summary> publicclassCommentHelper { ///<summary> /// Is the recaptcha solution valid? ///</summary> ///<returns> /// False, if the recaptcha is configured and the solution on postback is invalid; otherwise, true. ///</returns> publicstaticbool IsRecaptchaSolutionValid() { // Variables. var request = System.Web.HttpContext.Current.Request; // Don't validate GET requests. if ("get".InvariantEquals(request.HttpMethod)) { returntrue; }
// Don't validate when key isn't configured. var privateKey = ConfigurationManager.AppSettings[uCommentsyKeys.RecaptchaPrivateKey]; if (string.IsNullOrWhiteSpace(privateKey)) { returntrue; } // Only validate if the uCommentsy form was submitted with the ReCaptcha portion rendered. var flag = request.Form["uCommentsyReCaptchaSolutionFlag"]; if (!"true".InvariantEquals(flag)) { returntrue; } // Validate solution. returnReCaptcha.Validate(privateKey);
Comments not posting
Umbraco 6.1.1
uBlogsy 3.0
uCommentsy 1.0.0.1
When submitting a comment it just reloads the page.
I get a HTTP 200 from fiddler, no error. Same with dev tools.
How can i work out if its even calling uCommentsyContactFormSurfaceController?
Hi
Did you sort out this problem?
If the page is just releoading it sounds like the controller is not being called.
Do you have any special routes?
we never sorted it out, had to drop it and roll our own in the end as we were running out of time.
There were no special routes. As you say, it seemed like the controller wasnt being invoked.
I am having a similar problem, though for mine the page does a post back, and when the page is refreshed there is no indicator that the captcha was incorrect (works fine for correct captchas). I'm guessing this is because Google has moved their API URL for ReCaptcha. See here: https://groups.google.com/d/msg/recaptcha-announce/wf9oREIMnmM/raV_6oNg4kYJ
The reason I am guessing that is because my Fiddler2 capture of the traffic shows this (I replaced some sensitive information and the extraneous markup):
I tried to update http://www.nuget.org/packages/Microsoft.AspNet.Web.Helpers.Mvc/ (where the ReCaptcha functionality is apparently in), but that broke other functionality (I was getting a runtime error on any page with comments due to some version incompatibility between assemblies).
Actually, I'm thinking I may be mistaken. Maybe uCommentsy just doens't display an error message when the user gets the ReCaptcha wrong? Based on the code in uCommentsyFormContact.cshtml, it looks like there is some code to handle the case where the query string has a parameter of "success" set to "error". However, it does not redirect to that URL on error. Maybe that's intended for errors other than ReCaptcha mistakes?
Guess I'll poke around in the source code at https://bitbucket.org/anthonydotnet/ucommentsy to see what may be happening.
Making some progress. Looking in the action method (uCommentsyContactFormSurfaceController.Post), the only thing that I can see that might indicate a failed captcha is this line:
That is at the top of the action method. If that's the case, then any captcha failure would just return the current page, without any indication there was an error. I might be able to use that to test for failed comments, supposing there are not other forms on the page that use model state and supposing I can access ModelState from the view itself. Otherwise, this may require that I recompile uCommentsy and alter the behavior of that action method (e.g., to redirect to the error URL when the captcha fails).
Making further progress. I think I was wrong about the above code. This looks like the offending code:
Based on an article I just found (http://www.dotnetcurry.com/showarticle.aspx?ID=611), the ReCaptcha.Validate method is what does the validation. I suppose that method must look at Request.Form for the recaptcha answer (I looked it over before because I only saw the private key being passed as a parameter, but then realized it can access the HttpContext without it being passed as a parameter).
I can probably just do the same thing to test if the captcha response was valid and take some appropriate action (e.g., display message, redirect user).
Baldy it dawned on me that perhaps there could be a dll which was conflicting. This happened to me a long time ago. I cant remember what the fix was, although I think it had somehting to do with webapi :/
Nicholas, this may be a silly question, but I assume you have the recaptcha keys in your web.config?
Hi Anthony,
Yes, I have ReCaptcha keys in my web.config. I eventually got it working by creating a helper method to detect if the captcha solution was valid or not (I then display an error message to the user if their solution was invalid). I consider this to be a workaround and am not aware of there being a built-in method to ascertain whether or not the uCommentsy post was valid or not. Here is my helper method (note that I also render the "uCommentsyReCaptchaSolutionFlag" input field in the form to be sure it was actually the comment form being submitted):
Interesting. I'll need to look into this.
is working on a reply...