简体   繁体   English

操作超时错误

[英]Operation timed out error

I am hitting a wall with reCaptcha.net 我正在用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 . 一些背景-我正在使用从http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest获得的reCaptcha-dotnet v1.0.5。

I was able to develop a site and make it work locally with reCaptcha validation. 我能够开发一个站点,并通过reCaptcha验证使其在本地工作。 When I deploy it to the server (the site is hosted on 1and1.com), I am getting the error below - 当我将其部署到服务器(该站点托管在1and1.com上)时,出现以下错误-

The operation has timed out 操作已超时

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 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 异常详细信息:System.Net.WebException:操作已超时

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. 我已经检查了Google论坛,其中建议服务器允许来自端口80的出站连接。我试图向1and1.com的支持人员解释这一点,但我不认为他有任何线索。

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 : 这是我用于托管在1and1上的网站的邮件配置和Recaptcha代理的代码:

1- Web.config (only works if put there !) 1- Web.config(仅在放置时有效!)

<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 : 2-在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. 终于找到了解决方案,我从1and1获得了正确的代理服务器地址并使用了该地址。 reCaptcha works great now. reCaptcha现在运作良好。

Also, for some reason, setting the proxy value in the code using the IWebProxy property of the reCaptcha control did not work. 同样,由于某些原因,使用reCaptcha控件的IWebProxy属性在代码中设置代理值也不起作用。 I had to add the tag in web.config under . 我必须在的web.config中添加标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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