0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jupss
  • 7
  • 4
  • 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 Answers2

0

This link should show you how to check authentication and roles in the Razor page.

Checking Login and Roles In 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