0

I'm developing a blog in MVC, I need to know if the admin is logged, and if is logged then show him links for delete, edit, and create posts, for the other users they don't need to see those links, I was thinking in use a boolean Session variable for this, the value of the variable is true if admin is logged, otherwise false, I have read that we should avoid to use Session variables. Do you think is a good practice to do this using Session variable? I know that using [Authorize(Users ="admin@email.com")] I can give or deny access to actions depending on which user is logged. But how could I know IF the admin is logged using a condition?

For example: if(someCode.GiveMeUserNameLogged == "admin@email.com" ){//do other code} ???

AlexGH
  • 2,735
  • 5
  • 43
  • 76
  • 3
    If you're using roles then you can just do `if(User.IsInRole("admin"))`. You gotta be more specific. – Nico Nov 03 '16 at 16:56
  • 2
    Take it a look here: http://stackoverflow.com/questions/19087786/how-should-i-check-if-a-user-is-authenticated-in-mvc5 – sr28 Nov 03 '16 at 16:57

1 Answers1

1

I can do what I want with this sentence: if(User.Identity.Name=="adminUser"){//do some other stuff}

AlexGH
  • 2,735
  • 5
  • 43
  • 76