2011-05-19 30 views
0

我大概只是​​累了,沒有看到有什麼不對這個所以也許你人可以給我一個想法。使用自定義FormsAuthentication問題的FormsAuthenticationTicket

public class AuthTicket : IAuthTicket 
{ 
    #region IAuthTicket Members 

    public string CreateAuthenticationTicket(string userName, bool persistent, string userData) 
    { 
     var formsAuthenticationTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, 
                     DateTime.Now.AddDays(5), persistent, userData, 
                     FormsAuthentication.FormsCookiePath); 
     var encryptedTicket = FormsAuthentication.Encrypt(formsAuthenticationTicket); 

     return encryptedTicket; 
    } 

    #endregion 
} 

// This is injeted in the ctor 
string authTicket = _authTicket.CreateAuthenticationTicket(userId.ToString(), true, 
                      registerOpenIdUserViewModel.DisplayName); 
       Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,authTicket)); 


       return RedirectToAction("Index", "Home"); 

在我的控制器行動 我有一個部分與@ Html.ActionLink(「註銷」,「註銷」,「帳戶」) 在爲退出的行動,我只是有 FormsAuthentication.SignOut

那麼現在的問題是,SignOut不會刪除AuthTicket,我仍然看到的cookie和用戶不能註銷.. :)酷吧?

回答

0

我有同樣的問題。我只是手動強制cookies在我的代碼中被刪除。

Roles.DeleteCookie(); 
+0

LOL ...去圖右。我可以做到這一點,但我太OCD不能找出這一個。 – CrazyCoderz 2011-05-19 16:02:40

+0

@Assistant〜我在這塊岩石上打了我的頭。它堅持了一大堆的cookie,所以它重新創建了cookie的價值。類似的東西。如果您找到更多信息,請告訴我。 – jcolebrand 2011-05-19 16:05:46

+0

這似乎解決了這個問題。在我的web.config文件中,我在認證部分設置了loginUrl =「〜/ Account /」。我如果我們沒有使用這樣做讀什麼FormsAuthentication.SignOut確實有點.. http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx – CrazyCoderz 2011-05-19 16:27:42