Reputation: 83
I'm implementing one MVC application and authentication is done using active directory and login action is working properly.Now I want to show the logout link in layout using partial view, if the user is login for that I've created one partial view _LoginPartial in that view i want to show the logout link on the basis of whether the user is login or not.
Question:How to check user is logged-in or not?
Upvotes: 0
Views: 1237
Reputation: 6141
Within the action, use Request.IsAuthenticated:
if (Request.IsAuthenticated)
{
// Logic
}
And in Razor:
@if(User.Identity.IsAuthenticated)
{
// Your link here
}
Upvotes: 3