2012-12-18 33 views

回答

3

答案很簡單:使用FormsAuthentication.SignOut();

長的答案

public ActionResult LogOff() 
{ 
    FormsAuthentication.SignOut(); 

    return RedirectToAction("Login", "Account"); 
} 

private ActionResult RedirectToLocal(string returnUrl) 
{ 
    if (Url.IsLocalUrl(returnUrl)) 
    { 
     return Redirect(returnUrl); 
    } 
    else 
    { 
     return RedirectToAction("Index", "Home"); 
    } 
} 

使用[Authorize]您不希望用戶在註銷後執行的操作之上。您可以通過單獨在上面的操作中添加此屬性或使用[Authorize]標記整個類,以便所有方法現在只能由經過身份驗證的用戶訪問。

希望這會有所幫助。

+0

我應該在哪裏調用'FormsAuthentication.SignOut();' – Jonathan

+0

在您想要結束用戶會話的位置調用它。 – Yasser

+0

在登錄頁面控制器 – Jonathan

0
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); 

這應該在更新的版本中工作。