該代碼不正確設置的私有密鑰(或與此有關的公共密鑰)。在您的控制器中設置您的私鑰,在您的視圖中設置公鑰。
在你的控制器:
<HttpPost()> _
Public Function LogOn(ByVal model As LogOnModel, ByVal returnUrl As String) As ActionResult
If Microsoft.Web.Helpers.ReCaptcha.Validate(privateKey:=System.Configuration.ConfigurationManager.AppSettings("reCaptcha:privateKey")) Then
If ModelState.IsValid Then
If MembershipService.ValidateUser(model.UserName, model.Password) Then
FormsService.SignIn(model.UserName, model.RememberMe)
If Not String.IsNullOrEmpty(returnUrl) AndAlso Url.IsLocalUrl(returnUrl) Then
Return Redirect(returnUrl)
Else
Return RedirectToAction("Index", "Home")
End If
Else
ModelState.AddModelError("", "The user name or password provided is incorrect.")
End If
End If
Else
ModelState.AddModelError("", "The reCaptcha is incorrect!!")
End If
' If we got this far, something failed, redisplay form
Return View(model)
End Function
在視圖:
@ ReCaptcha.GetHtml(公鑰:= System.Configuration.ConfigurationManager.AppSettings( 「驗證碼:公鑰」),主題:=」紅「)
在web.config中:
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="reCaptcha:privateKey" value="6LceccMSAAAAAFi54eiELTCDUwrHjY-Qwot05Kip" />
<add key ="reCaptcha:publicKey" value="6LceccMSAAAAAO9u14kcJflcpGD6XnfjNf1KcKz6" />
</appSettings>
我的例子是VB.NET,但你應該能夠輕鬆地轉換它。
尚未在MVC環境中實現ReCaptcha,但這看起來是一個很好的開始參考的地方http://devlicio.us/blogs/derik_whittaker/archive/2008/12/02/using-recaptcha-with-asp -net-mvc.aspx它不是MVC3,但我不認爲這會有所作爲 – davidferguson 2011-03-25 21:54:59