Using reCaptcha with BlogEngine.net

两盒软妹~` 提交于 2019-12-06 14:22:04

Now 1.6.1 has inbuilt support for reCaptcha See Enable ReCaptcha

reCaptcha's default API does not work with AJAX-driven webpages, especially when you replace the content, where the reCaptcha resides. The problem here is the default reCaptcha API. Just switch to the AJAX API, which is also offered here

var captchaChallengeValue = filterContext.HttpContext.Request.Form["recaptcha_challenge_field"];
var captchaResponseValue = filterContext.HttpContext.Request.Form["recaptcha_response_field"];
var captchaValidator = new Recaptcha.RecaptchaValidator
{
    PrivateKey = "private key here",
    RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
    Challenge = captchaChallengeValue,
    Response = captchaResponseValue
};

var recaptchaResponse = captchaValidtor.Validate();

This is how I did it on a different site. I took what was entered and the response and then created a new captchaValidator which has a method that will check if the responses are valid. Then use that as your boolean for your if.

I am using ASP.Net MVC. But, I would assume that the idea is similar.

Hope this helps.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!