我想渲染用户当前已记录的注销按钮。
我想将按钮放在_Layout.cshtml页面中。
如何检查用户是否已登录?
答案 0 :(得分:2)
@if(Request.IsAuthenticated) {
@Html.ActionLink("Your text goes here.", "LogOff", "YourControllerName", null, null)
}
答案 1 :(得分:1)
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")
}