简体   繁体   中英

Operation timed out error

I am hitting a wall with reCaptcha.net

Some background - I am using reCaptcha-dotnet v1.0.5 which I got from http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest .

I was able to develop a site and make it work locally with reCaptcha validation. When I deploy it to the server (the site is hosted on 1and1.com), I am getting the error below -

The operation has timed out

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The operation has timed out

I have checked the google forums which advise to have the server allow outbound connections from Port 80. I tried to explain this to the support guy at 1and1.com but I don't think he has a clue at all.

Other than the above, is there anything I could do code-wise to resolve this? Has anybody figured a solution for this?

Appreciate any kind of advise!

This is the code I use for mail configuration and Recaptcha proxy for a web site that is hosted on 1and1 :

1- Web.config (only works if put there !)

<system.net>
    <mailSettings>
         <smtp from="mail@domain.com">
            <network host="smtp.1and1.com" port="25" userName="mymail@domain.com" password="mypassword"/>
         </smtp>
    </mailSettings>
    <defaultProxy>
        <proxy usesystemdefault = "false" bypassonlocal="false" proxyaddress="http://ntproxyus.lxa.perfora.net:3128" />
    </defaultProxy>
</system.net>

2- Inside a dedicated action in mycontroller :

// ouside the action I've defined the response
private class gapi {public bool success{get;set;}}

public bool SendMail(string firstname, string lastname, string email, string message, string grecaptcha)
{
    SmtpClient smtp = new SmtpClient("smtp.1and1.com");
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(email);
    mail.To.Add("mail@domain.com");
    mail.Subject = firstname + " " + lastname;
    mail.Body = message;
    try
    {
        using (var client = new WebClient())
        {
            var values = new NameValueCollection();
            values["secret"] = "6LcEnQYTAAAAAOWzB44-m0Ug9j4yem9XE4ARERUR";
            values["response"] = grecaptcha;
            values["remoteip"] = Request.UserHostAddress;

            var response = client.UploadValues("https://www.google.com/recaptcha/api/siteverify","POST", values);
            bool result = Newtonsoft.Json.JsonConvert.DeserializeObject<gapi>((Encoding.Default.GetString(response) as string)).success;
            if(!result) return "Something is wrong)";
        }
        //... verify that the other fields are ok and send your mail :)
        smtp.Send(mail);
    }
    catch (Exception e) { return "Something is wrong)"; }

    return "Okey :)";
}

Hope this helps.

Finally got the solution, I got the correct proxy server address from 1and1 and used that. reCaptcha works great now.

Also, for some reason, setting the proxy value in the code using the IWebProxy property of the reCaptcha control did not work. I had to add the tag in web.config under .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM