2

お問い合わせフォームにGoogle ReCaptchaBitArmory NuGetパッケージを使用しています。Azure のログを確認したところ、BitArmory ReCaptcha ( siteKey: can not be null?? ) からエラー応答を受け取っている人がいることがわかりました。

サイトキーを保存する方法を複数試しています。私の共通のグローバル変数の最初に。次に、関数内にローカル文字列変数を作成し、captcha 関数に挿入しました。最後のステップは、サイトのキー文字列をキャプチャにハードコーディングすることでした。すべてのケースで同じ結果が得られますが、一部の人々は引き続きsiteKey:can not be null という応答を受け取りますか???

ここに私のフォームの私のフォーム部分があります:

@section head {
<script src="https://www.google.com/recaptcha/api.js?render=xxxxxxx"></script>
}

 <form id="contactForm" class="form-horizontal" role="form" method="post" action="/site/comments">
                   <div class="form-group">
                       <label for="captcha"></label>
                       <input id="captcha" class="form-control" type="hidden" name="captcha" value=""/>
                   </div>
                   <div class="form-group">
                       <label for="email" class="col-lg-2 control-label">Email</label>
                       <div class="col-lg-10">
                           <input id="email" type="text" class="form-control" value="@ViewBag.Email" name="email" placeholder="me@email.com"/>
                       </div>
                   </div>

div class="col-lg-10">
                           <input type="submit" id="submitBtn" onclick="SubmitClicked()" class="btn btn-primary" value="Send us your feedback!"/>
                       </div>
<script type="text/javascript">
 function SubmitClicked() {
          $("#submitBtn").attr('disabled', true);
          ExecuteReCaptcha();
        }
function ExecuteReCaptcha() {
            grecaptcha.ready(function() {
              grecaptcha.execute('xxxxxxxx', {action: 'xxxxx'})
                .then(function(token) {
                   // Set `token` in a hidden form input.
                   $("#captcha").val(token);
                   // POST Form
                  postForm();
                });
            });
          }
function postForm() {
  $("#contactForm").submit();

そして私のサーバー側:

[HttpPost]
        public async Task<ActionResult> Comments(string email, string captcha, string regarding, string comment)
        {
            var clientIp = Request.UserHostAddress;
            var token = captcha;
            var secret = "xxxxxxxxx";
            var captchaApi = new ReCaptchaService();
            var results = await captchaApi.Verify3Async(token, clientIp, secret);

            if (IsValidEmail(email) && (!results.IsSuccess || results.Score < 0.5 || results.Action != "xxxxxx"))
            {
                ErrorViewModel eVm = new ErrorViewModel
                {
                    message = "\"" + email + "\" is not a valid email address.",
                    bShowBackButton = true
                };
                return View("Error", eVm);
            }

一部のクライアントは応答を取得しています。

System.ArgumentException: The client response must not be null or empty
Parameter name: siteSecret
   at BitArmory.ReCaptcha.ReCaptchaService.<Verify3Async>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at BootstrappingMVC.Controllers.SiteController.<Comments>d__37.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)

4

1 に答える 1