c# - Programmatically authorize a Windows user against a string of users? -



c# - Programmatically authorize a Windows user against a string of users? -

programmatically, can authorize windows user based on whether in particular role this:

if(!user.identity.isauthenticated) homecoming false; var isauthroized = user.isinrole(@"domain\some role"); // ... homecoming isauthorized;

what can't figure out how do, how match user's name if, instance, list of individual users given access.

so imagine you're trying authenticate user against given string of authorized users, using normal authorizeattribute:

[authorize(users = @"domain\user1, domain\user2, domain\user3")] public actionresult someaction(){ ... }

how programmatically authorize user against string of users?

@"domain\user1, domain\user2, domain\user3"

edit: ok, point of confusion: point of specifying multiple users if have (in normal authorizeattribute) declaration follows:

[authorize(users=@"user1,user2,user3", roles=@"somerole"] // can this: user.isinrole(roles); // what's equivalent specified users? user.identity.name.isinnames(names); // <-- how done programmatically?

i'm off mark here, , missing piece of information. please enlighten me!

edit 2: mvc source demystified of me. indeed done similar suggested in 1 of answers below:

if (_userssplit.length > 0 && !_userssplit.contains(user.identity.name, stringcomparer.ordinalignorecase)) { homecoming false; }

i utilize hashset, testing existence of user fast operation collection type.

first, split string, , add together hashset.

string[] splittedusers = usersstring.split(new string[] { ", " }, stringsplitoptions.removeemptyentries); var users = new hashset<string>(splittedusers);

test user this

string user = "xy"; if (users.contains(user)) { // user }

c# .net windows asp.net-mvc-3

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -