I have two Asp.Net Core MVC apps and login system on IdentityServer4. First app is fully protected, means all controllers are behind [Authorize] attribute and that one works fine. Second app is public app and has no any [Authorize] attributes.
Issue is on second app on line
@if (User.Identity.IsAuthenticated)
{
<a href="#">@User.Identity.Name</a>
}
because User.Identity.IsAuthenticated is always false. This piece of code is on razor page which is called from simple action
public IActionResult Index()
{
return View();
}
What I figured out is when I add [Authorize] attribute on this action then there is call to IDS4 'connect/authorize' endpath and User.Identity.IsAuthenticated is authenticated and all works fine.
Trouble is that action should be without [Authorize] attribute and I just want to show user name and/or user email if user is logged in.
Is there any other way to verify cookie and get user info in User.Identity?