I’m using WindowsTokenRoleProvider to determine Active Directory group membership in an ASP.NET web application.
My problem is that performance is not good, especially when a user is in many groups. As an example, I am in 253(!) groups, and WindowsTokenRoleProvider is taking around 150 seconds to determine what groups I am in.
I know I can use caching so that this isn’t done on subsequent requests for a user, but obviously it isn’t acceptable to take that long on the first hit.
What are my options? Can I force WindowsTokenRoleProvider to only consider certain groups? (I’m only interested in 5).
Some testing has revealed that my problem is that calling:
is accessing the method
GetRolesForUserin theRoleProvider– which is retrieving details of every role the user is a member of.But calling:
determines whether or not the user is in the group – without retrieving the details of every role the user is in.
Weird, but it looks like using
Roles.Provider.IsUserInRolewill solve my problem.* UPDATE *
It turns out that this is just a partial workaround; if I use imperative permission checks, or ‘allow’ and ‘deny’ in web.comfig, then
WindowsTokenRoleProviderstill goes and slowly gets details of every group the user is a member of :o(So my question still stands…
* UPDATE *
I solved this by creating a class that extends from WindowsTokenRoleProvider and overriding
GetRolesForUserso it only checks for membership of roles specified in the configuration. It includes caching too: