I've got an simple login system. Whenever a user is logged in, I want them to see a specific HTML div. Only if you've logged in. For the users that haven't logged in, I want this element to be hidden. I've read something about "roles" but I don't know if this was the right concept to apply in this situation. Could someone give me advice about how I could fix this problem.
Asked
Active
Viewed 1,428 times
0
-
How have you implemented logins? Are you using the ASP.NET Core Identity API? Are you using one of the build in Authentication schemes? – Conman_123 May 16 '20 at 11:04
2 Answers
0
This link should show you how to check authentication and roles in the Razor page.
0
If you are using Identity you could check utilize on this
User.Identity.Name;
User.Identity.IsAuthenticated;
If you are using custom (cookie) authentication, you can also leverage read/write the user inside the cookie. Put it on Viewbag or direct access it on the Razor page.
For more information and/or external login providers, you can check this out bro https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-3.1&tabs=visual-studio

VhaL
- 26
- 3
-
User or User.Identity is not part of EF. You could try typing it on a new project. – VhaL May 18 '20 at 00:22