I did it in my rc1 project like:
User.Claims.ElementAt(#).Value
But after I switched to rtm it wouldn’t work anymore. When I debug the Razor view the object looks the same but User.Claims is just empty. Any idea what the reason could be.
I did it in my rc1 project like:
User.Claims.ElementAt(#).Value
But after I switched to rtm it wouldn’t work anymore. When I debug the Razor view the object looks the same but User.Claims is just empty. Any idea what the reason could be.
Assuming you have claims attached to the current principal. In your Razor view:
This will give you access to the ClaimsIdentity of the current user. In an effort to keep your claims fetching clean you may want to create an extension method for searching claims.
Then you can just access whatever claim you want with:
Hope this helps.
Quick search for claims identity in razor view came up with a similar question and answer: MVC 5 Access Claims Identity User Data
In Core 3.0, use view authorization
Startup.cs
Then inside the UI
View-based authorization in ASP.NET Core MVC