【发布时间】:2011-07-24 18:29:19
【问题描述】:
我有此代码来检查组成员身份,但它似乎需要很长时间才能响应并减慢我的应用程序,响应需要将近 7-12 秒,我只需要检查一个特定的组成员身份,是有更快的方法吗?
public static bool isInRole(UserAccount userAccount, string groupName)
{
using (var ctx = new PrincipalContext(ContextType.Domain, userAccount.DomainName))
{
using (var grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName))
{
bool isInRole = grp != null &&
grp
.GetMembers(true)
.Any(m => m.SamAccountName == userAccount.UserName);
return isInRole;
}
}
【问题讨论】:
-
您能否将响应缓存一段可接受的时间?
-
我该怎么做?我正在使用 WCF 服务 .net 4.0
-
组员多吗?如果是这样,您可能会通过查找用户帐户的组是否包含您要查找的组而不是查找组的成员是否包含您要查找的帐户来获得更快的响应。
-
@adrianbanks 我该怎么做
-
我已经有一段时间没有自己做了这个并且没有 VS 手头 - userAccount 对象是否有
Groups属性/GetGroups()函数?
标签: c# active-directory