Attempting to use the new reCaptcha on my website but it's timing out during the validation. Here is the stack trace;

[WebException: The operation has timed out]
   System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) +283
   System.Net.WebClient.DownloadString(Uri address) +100
   System.Net.WebClient.DownloadString(String address) +29
   PROJECTNAME.Controllers.AboutController.validate(String name, String company, String phone, String email, String subject, String body, Nullable`1 remember) +106
   lambda_method(Closure , ControllerBase , Object[] ) +360
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +182
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
   System.Web.Mvc.Controller.ExecuteCore() +105
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +87
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9658396
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

This is the basic controller that i'm using to validate;

[HttpPost]
[ActionName("ContactUs")]
public ActionResult validate(string name, string company, string phone, string email, string subject, string body, bool? remember)
{

    var r = Request["g-recaptcha-response"];

    string reply;
    using (var wc = new System.Net.WebClient())
    {
        reply = wc.DownloadString(string.Format(
        "https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", SECRETKEYREMOVED, r));

    }

    var captchaResponse = JsonConvert.DeserializeObject<CaptchaResponse>(reply);

    if (captchaResponse.Success == "true")
    {
        try
        {
            Do stuff to send msg

            return RedirectToAction("ContactSent");
        }
        catch (Exception ex)
        {
            ViewData.ModelState.AddModelError("_FORM", ex.ToString());
        }

    }

    else
    {

        return RedirectToAction("ContactFailed");
    }


    return View();
}

And the Model...

namespace TVCWeb.Models
{
    public class CaptchaResponse:viewModelBase
    {
        [JsonProperty("success")]
        public string Success { get; set; }

        [JsonProperty("error-codes")]
        public List<string> ErrorCodes { get; set; }
    }
}

And also the View..

    @using (Html.BeginForm())
    { 

    //ALL THE RANDOM STUFF ON THE PAGE, TABLE for input ETC

<div class="g-recaptcha" data-sitekey="datakeyremoved"></div>

        <div class="contactButtons">
            <input type="submit" value="Send" id="send" />
        </div>

I am struggling to find where the server is hanging with the validation. The contact form works perfectly fine without the Captcha but when added it just hangs. I've tried out a few different ways to do this but none of them seem to be working. Is it possible it's an issue with the Web Hosts?

Any help out there? Thanks

Related posts

Recent Viewed