0

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?

1
  • How are you handling authentication/membership? Commented Oct 4, 2012 at 15:29

2 Answers 2

2
@if(Request.IsAuthenticated) {
    @Html.ActionLink("Your text goes here.", "LogOff", "YourControllerName", null, null)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please show me how I can call the action which has the LogOff code? The action is called LogOff and it's inside ActionController
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")

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.