如果用户当前已登录,我想呈现注销按钮。
我想把按钮放在 _Layout.cshtml 页面中。
如何检查用户是否已登录?
@if(Request.IsAuthenticated) {
@Html.ActionLink("Your text goes here.", "LogOff", "YourControllerName", null, null)
}
If you are using Form Authentication , try
// Inside Controller
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Home");
}
// Inside View (Layout Page) Razor Engine
@if(User.Identity.IsAuthenticated){
@Html.ActionLink("Your text goes here.", "LogOff", "YourControllerName")
}