authorization - ASP.Net Roles and Membership check for Users in role for multiple roles -
i have users in membership , 1 user can have 1 or more 1 roles assigned. want check specific roles of page example:
role1, role2, role3, role4, role5
users have access of role2 , role3 can access page1.aspx , if user have access of role1 , role2 can access because role2 there available.
i have implemented membership , have list of user's roles string array of
string[] roles = roles.getrolesforuser(user.identity.name);
how can check against multiple roles? may need 1 one check using roles.isuserinrole function?
i have used; returns 0 count because of partner in capital. how can ignore case? , below right way check array against array?
string[] userroles = { "partner", "testsetsr" }; string[] requiredroles = { "contractor", "customer", "sims", "nonclientau", "partner" }; var countinroles = userroles.intersect(requiredroles).count();
you have implement own authorization filter attribure. can create class extending 'authorizationattribute', override onauthorization can specify required role-checks.
a small example on how here in nimesh's .net blog
the example not solution personal problem, should give idea need do.
edit: same goes applications role-provider, extend , override isuserinrole (or maybe better add new method) provide checks need in order have roles.isuserinrole work way want.
to 2nd question: if have 2 arrays , want count how many members of 1st array members of 2nd while ignoring case can using linq
var countinroles = userroles.select(u => u.tolower()).count(u => requiredroles.select(r => r.tolower()).contains(u));
on other hand, lets vice versa lists if have list of required roles access action can check if user has required roles using linq (again ignoring case)
string[] requiredroles = { "partner", "testsetsr" }; string[] userroles = { "contractor", "testsetsr", "customer", "sims", "nonclientau", "partner" }; var userhasallrequiredroles = requiredroles.select(r => r.tolower()).all(r => userroles.select(u => u.tolower()).contains(r));
Comments
Post a Comment