I want to show some div at the view only if user has logged in.
That's how I tried to do it:
@{
if (Request.IsAuthenticated)
// if (User.Identity.IsAuthenticated)
{
<div>
Some content only for logged in users.
</div>
}
}
But Request.IsAuthenticated (and User.Identity.IsAuthenticated) is always true, even in the very beginning, right after I start the website from Visual Studio. Apparently, it gets me as the user logged in Windows (because User.Identity.Name returns my Windows login), but I need it to check if user has authenticated on website via FormsAuthentication.
That's my web.config:
<authentication mode="Forms">
<forms loginUrl="/Account/Login" timeout="2880" />
</authentication>
How do I check if users has logged in via FormsAuthentication?
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null), but that doesn't seem to be the right way.