尝试通过我的网络应用程序连接到Facebook后,无法创建SSL/TLS安全通道

arg*_*nza 7 c# asp.net ssl facebook facebook-graph-api

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

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

我的主页上的Page_Load中有这段代码:

 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);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

这段代码在"使用Facebook登录"按钮的"点击"代码中:

FaceBookConnect.Authorize("user_photos,email", Request.Url.AbsoluteUri.Split('?')[0]); 
Run Code Online (Sandbox Code Playgroud)

我试图将关于Facebook连接的所有代码从Page_Load移动到Click动作,这样它只会在用户按下按钮时尝试连接,但由于某种原因它不起作用......

我不确定要做什么,因为代码是我从网上拿来的东西,而不是由我制作的,希望你能告诉我如何只在需要时刷新或连接到Facebook服务器..谢谢!

Gil*_*hen 0

如果您怀疑您的 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;
                }
            }
Run Code Online (Sandbox Code Playgroud)