由于某些原因,GetAuthorizationGroups()似乎需要大约20秒才能返回群组.我正在使用此代码:
UserPrincipal user;
// This takes 20 seconds
user.GetAuthorizationGroups().OfType<GroupPrincipal>().ToList();
Run Code Online (Sandbox Code Playgroud)
任何人有任何想法或只是一个缓慢的AD域?(例如,在Outlook中查看组不需要很长时间)
当用户登录网站时,我正在使用以下代码在Active Directory中查找信息.对本地域运行它非常快,但是通过VPN运行到远程可信域,它非常慢(需要大约7或8秒).将dsa.msc从同一个盒子运行到远程域几乎和在本地运行它一样快.
我正在使用属性过滤来检索可能的最小数据量,因此在这种情况下System.DirectoryServices是否存在某些内在缓慢的问题,或者是否有人对如何提高性能有任何提示?
通过VPN的网络连接很好,只有这个代码运行缓慢.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (var LDAPConnection = new DirectoryEntry("LDAP://domain/dc=domain,dc=com", "username", "password"))
{
LDAPConnection.AuthenticationType = AuthenticationTypes.Secure;
using (DirectorySearcher Searcher = new DirectorySearcher(LDAPConnection))
{
Searcher.Filter = "(&(&(objectclass=user)(objectcategory=person))sAMAccountName=username)";
Searcher.PropertiesToLoad.Add("mail");
SearchResult result = Searcher.FindOne(); //this line takes ages!
string EmailAddress = result.Properties["mail"][0].ToString();
Console.WriteLine(EmailAddress);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)