WindowsTokenRoleProvider 性能不佳
我使用 WindowsTokenRoleProvide
r 来确定 ASP.NET Web 应用程序中的 Active Directory 组成员身份。
我的问题是性能不好,尤其是当用户位于多个组中时。例如,我在 253(!) 个组中,WindowsTokenRoleProvider
需要大约 150 秒来确定我所在的组。
我知道我可以使用缓存,这样就不会在后续操作中执行此操作请求用户,但显然在第一次点击时花费那么长时间是不可接受的。
我有什么选择?我可以强制 WindowsTokenRoleProvider
仅考虑某些组吗? (我只对5感兴趣)。
I'm using WindowsTokenRoleProvide
r 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些测试表明我的问题是调用:
正在访问 RoleProvider 中的方法 GetRolesForUser ,该方法正在检索用户所属的每个角色的详细信息。
但是调用:
确定用户是否在组中 - 无需检索用户所在的每个角色的详细信息。
很奇怪,但看起来使用
Roles.Provider.IsUserInRole
可以解决我的问题。* 更新*
事实证明,这只是部分解决方法;如果我在 web.comfig 中使用命令式权限检查或“允许”和“拒绝”,则
WindowsTokenRoleProvider
仍然会继续运行,并且缓慢获取用户所属的每个组的详细信息:o(所以我的问题仍然存在...
* UPDATE *
我通过创建一个从 WindowsTokenRoleProvider 扩展的类并覆盖
GetRolesForUser
解决了这个问题,因此它只检查配置中指定的角色也包括缓存:Some testing has revealed that my problem is that calling:
is accessing the method
GetRolesForUser
in 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.IsUserInRole
will 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
WindowsTokenRoleProvider
still 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
GetRolesForUser
so it only checks for membership of roles specified in the configuration. It includes caching too: