Subby
Subby

Reputation: 5480

ASP.NET MVC 3 Log Off

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

Answers (2)

Vijayant Katyal
Vijayant Katyal

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

Justin Helgerson
Justin Helgerson

Reputation: 25551

@if(Request.IsAuthenticated) {
    @Html.ActionLink("Your text goes here.", "LogOff", "YourControllerName", null, null)
}

Upvotes: 2

Related Questions