2010-10-19 35 views
0

我成功實施了Facebook連接,並且能夠使用Facebook工具包檢索用戶信息。但我無法成功註銷。 當我按下Facebook的註銷按鈕無法刪除我在Facebook Connect後得到的Cookies

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

我還有五個Facebook的餅乾(當我登錄,因爲我使用的autologoutlink屬性自動出現): MyApiKey MyApiKey_ss MyApiKey_SessionKey MyApiKey_expires MyApiKey_user

我登出後,我真的在Facebook的註銷,因爲我需要在facebook.com再次登錄,但isConnected()總是返回true,我仍然可以檢索用戶的信息:

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

這可能是在黑暗中拍攝的,但是您確定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> 

這是我之前造成的問題。