2015-09-06 133 views
0

我一直跟着簡短而親切的教程:Integrating google recaptcha谷歌的Recaptcha總是假

我已經做了相關修改,我的看法如下所示:

<div class="form-group" style="margin-left: 7%;"> 
    @Html.Recaptcha("MyKeyGoesHere", CaptchaTheme.Dark) 
    @Html.ValidationMessage("ReCaptcha") 
</div> 

我的控制器看起來是這樣的:

[HttpPost] 
    [ValidateAntiForgeryToken()] 
    [CaptchaValidator] 
    public ActionResult SignUp(RegistrationSignUp model, bool captchaValid) 
    { 
     if (ModelState.IsValid) // Make sure all fields are field out. 
     { 
     } 

     return View(model); 
    } 

但captchaValid是,即使我已經選中複選框總是假的?我錯過了什麼嗎?任何幫助,將不勝感激。

回答

0

試試這個;

var response = Request["g-recaptcha-response"]; 
if (response != null && ReCaptcha.IsValid(response)) 
{ 
     // 
}