C# 尝试通过我的web应用连接到Facebook时,一段时间后无法创建SSL/TLS安全通道

C# 尝试通过我的web应用连接到Facebook时,一段时间后无法创建SSL/TLS安全通道,c#,asp.net,facebook,facebook-graph-api,ssl,C#,Asp.net,Facebook,Facebook Graph Api,Ssl,在我的web应用程序中,我添加了一个使用Facebook注册/登录的选项, 它工作得很好,做得很好,我正在使用C#和ASP.NET中的VS2013编码,当我开始调试并按下按钮时,它连接到Facebook并获取所有需要的信息 当我开始调试并按下Facebook按钮一段时间后,问题就开始了,我已经知道这是某种超时,但我不知道如何解决它 我的页面中有一段代码\u加载到我的母版页上: System.Net.ServicePointManager.SecurityProtocol = System.Ne

在我的web应用程序中,我添加了一个使用Facebook注册/登录的选项, 它工作得很好,做得很好,我正在使用C#和ASP.NET中的VS2013编码,当我开始调试并按下按钮时,它连接到Facebook并获取所有需要的信息

当我开始调试并按下Facebook按钮一段时间后,问题就开始了,我已经知道这是某种超时,但我不知道如何解决它

我的页面中有一段代码\u加载到我的母版页上:

 System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
        FaceBookConnect.API_Key = "**************";
        FaceBookConnect.API_Secret = "**************************";
        if (!IsPostBack)
        {
            if (Request.QueryString["error"] == "access_denied")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
                return;
            }

            string code = Request.QueryString["code"];
            if (!string.IsNullOrEmpty(code))
            {
                string data = FaceBookConnect.Fetch(code, "me");
                FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
                faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture?width=9999", faceBookUser.Id);
                string fname = faceBookUser.Name.Substring(0, faceBookUser.Name.IndexOf(' '));
                string lname = faceBookUser.Name.Substring(faceBookUser.Name.IndexOf(' ') + 1);
                string email = faceBookUser.Email + "@FB";
                string pictureurl = faceBookUser.PictureUrl;
                string gender = faceBookUser.Gender;
                if (SQLDB.CheckMailExists(email))
                {
                    FormsAuthentication.SetAuthCookie(email, true);
                    FormsAuthentication.RedirectFromLoginPage(email, true);
                }
                else
                {
                    SQLDB.AddFBUser(fname, lname, email, gender, pictureurl);
                    FormsAuthentication.SetAuthCookie(email, true);
                    FormsAuthentication.RedirectFromLoginPage(email, true);
                }
            }
        }
我试图将所有关于Facebook连接的代码从页面加载移动到点击操作,这样只有当用户按下按钮时,它才会尝试连接,但由于某些原因它无法工作


我真的不知道该怎么做,因为代码是我从网络上获取的,不是我自己制作的,希望你能告诉我如何在需要时刷新或连接到Facebook服务器。。谢谢

如果您怀疑您的Facebook连接超时,您应该将其作为任何其他异常处理,并重新重定向到您的登录页面。 这是我的密码:

catch (Exception ex)
            {
                if (ex is AggregateException && ex.InnerException is Facebook.FacebookOAuthException && usedState != null && HttpContext.Current != null)
                {
                    HttpContext.Current.Response.Redirect("~/FacebookLogin.aspx?logout=true");
                }
                else
                {
                    throw;
                }
            }

您使用的第三方SDK是什么?您是否阅读了有关其工作原理的文档?我建议您使用有文档记录的SDK,并了解其工作原理,例如您的代码片段没有提供足够的信息,说明您如何实现登录或问题发生的确切位置。也许您可以添加一个链接,从中获取代码?
catch (Exception ex)
            {
                if (ex is AggregateException && ex.InnerException is Facebook.FacebookOAuthException && usedState != null && HttpContext.Current != null)
                {
                    HttpContext.Current.Response.Redirect("~/FacebookLogin.aspx?logout=true");
                }
                else
                {
                    throw;
                }
            }