使用reCaptcha for asp.net library,以前一直工作正常,最近发现运行不正常了,google到了一个解决方案,不适用control而直接使用api,代码如下:

markup:

<div>
    <asp:Literal ID="litResult" runat="server" Mode="Encode" />
    <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=<%= RecaptchaPublicKey %>">
    </script>
    <asp:Button ID="btnSubmit" OnClick="btnSubmit_Click" Text="Submit" runat="server" />
</div>

 code behind:

private const string RECAPTCHA_CHALLENGE_FIELD = "recaptcha_challenge_field";
private const string RECAPTCHA_RESPONSE_FIELD = "recaptcha_response_field";

protected string RecaptchaPublicKey {
  get { return ConfigurationManager.AppSettings["RecaptchaPublicKey"]; }
}

protected void btnSubmit_Click(object sender, EventArgs e) {
  var validator = new Recaptcha.RecaptchaValidator {
    PrivateKey = ConfigurationManager.AppSettings["RecaptchaPrivateKey"],
    RemoteIP = Request.UserHostAddress,
    Challenge = Context.Request.Form[RECAPTCHA_CHALLENGE_FIELD],
    Response = Context.Request.Form[RECAPTCHA_RESPONSE_FIELD]        
  };
  if (validator.Validate().IsValid) {
    litResult.Text = "All Good";
  } else {
    litResult.Text = "The words you entered are incorrect";
  }
}

 

 

 

相关文章:

  • 2021-05-27
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-04-15
  • 2021-10-01
猜你喜欢
  • 2021-08-14
  • 2021-06-10
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-04-26
相关资源
相似解决方案