0

Currently I'm doing a check :

@if(this.User.Identity.Name=="DOMAIN\\USERID"){

This works great but I'd like to have multiple users(2-3) to check for. I'd also like to not have it hard coded. Is there a way to do this in the web.config or in a database?

webdad3
  • 8,893
  • 30
  • 121
  • 223

2 Answers2

1

You could add a list in the config...User1,User2 etc and then use linq and .Any() against this list?

    var users = "user1,user2,user3".Split(','); //list will come from your config
    bool result = users.Any(u => u == this.User.Identity.Name);

Also, since you're using MVC, if you want to use authorization for controllers etc, you can use the [Authorize] attribute. See this SO link too Authorize attribute in ASP.NET MVC

Community
  • 1
  • 1
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
1

Maybe use roles instead then add the relevant users to that role? This would make it easier to expand on in the future, plus you don't have to hard code a list of users.

Adam
  • 533
  • 4
  • 12