this is my code which works fine.If I'm authorized it works, if not, it redirects me to the identity server and after login back.
[Authorize]
public async Task<IActionResult> Index()
{
return View("../Secure/Index");
}
I want to return another view if user is not authorized and not to redirect him to the indentity server. This is how I tried it.
public async Task<IActionResult> Index()
{
if (User == null || User.Identity == null || !User.Identity.IsAuthenticated )
{
return View("../Public/Index");
}
return View("../Secure/Index");
}
However it is not working. User.Identity.IsAuthenticated is always false. Even when I was before on identity server and logged in. It seems that [Authorize] attribute is doing something more probably settings User.Identity.IsAuthenticated.
My question is, how do I know I'm authorized without attribute ?
Thank you