代码之家  ›  专栏  ›  技术社区  ›  Pascal Klein

无法删除我在Facebook连接后获得的Cookie

  •  0
  • Pascal Klein  · 技术社区  · 15 年前

    当我按下facebook注销按钮时(当我登录时会自动显示,因为我正在使用autologutlink属性)

    <fb:login-button autologoutlink="true"></fb:login-button>
    

    我还有五个Facebook Cookies: 八哥 MyApiKey_会话密钥 MyApiKey_过期 MyApiKey_用户

    在我注销之后,我真的在Facebook上注销了,因为我需要再次登录Facebook.com,但是 isConnected()

    var connectSession = new ConnectSession(ConfigurationManager.AppSettings["ApiKey"], ConfigurationManager.AppSettings["Secret"]);
    if (connectSession.IsConnected())
    {
       var api = new Api(connectSession);
       filterContext.Controller.ViewData["FBUser"] = api.Users.GetInfo();
    }
    

    首先,我不明白为什么我还可以检索用户信息,即使我不再登录,其次:我如何删除这个Cookies。以下代码不起作用:

    public static void ClearFacebookCookies()
        {
            String[] shortNames = new String[] { "_user", "_session_key", "_expires", "_ss", "" };
            HttpContext currentContext = HttpContext.Current;
            if (currentContext == null)
            {
                return;
            }
            string appKey = ConfigurationManager.AppSettings["APIKey"];
            if (appKey == null)
            {
                throw new Exception("APIKey is not defined in web.config");
            }
            foreach (var name in shortNames)
            {
                string fullName = appKey + name;
                HttpCookie cookie = currentContext.Response.Cookies[fullName];
                if (cookie != null)
                {
                    cookie.Value = null;
                    cookie.Expires= DateTime.Now.AddDays(-1d);
                }
                HttpCookie cookieRequest = currentContext.Request.Cookies[fullName];
                if (cookieRequest != null)
                {
                    cookieRequest.Value = null;
                    cookieRequest.Expires = DateTime.Now.AddDays(-1d);
                }
            }
        }// end Method
    
    1 回复  |  直到 11 年前
        1
  •  1
  •   ScottE    15 年前

    这可能是在黑暗中拍摄的,但是你确定fb.init就放在关闭body标签之前吗?

    <script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US"></script>
        <script type="text/javascript">FB.init('somekey');</script>
    

    这以前给我带来了麻烦。

    推荐文章