In all examples so far I saw examples how to show completely different views -- one for the case when the user is logged in, the other when the user is not logged in.
And I would like to display the same elements, just enable/disable some depending if the user is logged in or not. I though I can go with reading context.User.Identity.IsAuthenticated
and use it like this:
<NavLink class="nav-link" href="foobar"
IsDisabled="@(!(context.User.Identity?.IsAuthenticated ?? false))">
...
</NavLink>
But this requires context
. This property is provided by AuthorizeView
and this component in turn enforces the aforementioned strict split between two sets of views.
So how to achieve just enable/disable with single common view?
I am fully aware it is not security measure of any kind.
Update Both answers work with the same effect (thank you once again), but with small caveat -- just right after logging in both methods still returns info user is not authenticated. Here is the follow-up question: How to get fresh information whether the user is logged in?