2012-12-18 73 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); 

这应该在更新的版本中工作。