ASP.NET MVC 3注销

时间:2012-10-04 15:26:01

标签: asp.net-mvc

我想渲染用户当前已记录的注销按钮。

我想将按钮放在_Layout.cshtml页面中。

如何检查用户是否已登录?

2 个答案:

答案 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")

}