Reputation: 5480
I want to render a Log Off buttont IF a user is currently logged.
I want to put the button inside the _Layout.cshtml page.
How do I check if a user is logged in?
Upvotes: 0
Views: 499
Reputation: 660
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")
}
Upvotes: 1
Reputation: 25551
@if(Request.IsAuthenticated) {
@Html.ActionLink("Your text goes here.", "LogOff", "YourControllerName", null, null)
}
Upvotes: 2