mercredi 27 janvier 2016

Implementing reCaptcha into MVC3 failed because connected host failed to respond

Been attempting to implement reCaptcha into a contact form, which seems to work fine when hosted locally, but when uploaded it gives this error;

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.58.199.68:443

    [SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 216.58.199.68:443]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +208
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +464

The error happens after I submit the contact form, so possibly an issue with the verification to google?

This is the code i'm just testing with at the moment. When hosted through Visual Studio I get an error because the SMTP server i'm using doesnt exist since it's not being hosted.

But when it's Hosted live, it receives the above error.

Controller - 

[HttpPost]
        [ActionName("ContactUs")]
        public ActionResult validate(string name, string company, string phone, string email, string subject, string body, bool? remember)
        {
            var r = Request.Params["g-recaptcha-response"];
            using (var wc = new WebClient())
            {
                var validateString = string.Format(
                    "http://ift.tt/1xSi4Qj}",
                   "MY_KEY_USUALLY_GOES_HERE",    // secret recaptcha key
                   r); // recaptcha value
                // Get result of recaptcha
                var recaptcha_result = wc.DownloadString(validateString);
                // Just check if request make by user or bot
                if (recaptcha_result.ToLower().Contains("false"))
                {
                    return RedirectToAction("ContactFailed");
                }

                else
                {
                    Do stuff to send the contact message
                }
            }

My first guess would be that it's an issue with my Web Hosts blocking the connection but I'm pretty stumped.

Thanks

Aucun commentaire:

Enregistrer un commentaire