Tag: principalcontext

使用PrincipalSearcher.FindAll()时内存泄漏

我也有使用插件和appdomains的长时间运行服务,并且由于使用目录服务而导致内存泄漏。 请注意,我使用的是system.directoryservices.accountmanagement,但我理解它使用相同的底层ADSI API,因此容易出现相同的内存泄漏。 我查看了所有CLR内存计数器,并且内存没有泄漏,并且都是在强制GC或卸载appdomain时返回的。 泄漏是私有字节,不断增长。 我在这里搜索并看到了一些与使用ADSI API时内存泄漏相关的问题,但它们似乎表明只需遍历directorysearcher即可解决问题。 但正如您在下面的代码中看到的那样,我在foreach块中执行此操作,但内存仍然被泄露。 有什么建议? 这是我的方法: public override void JustGronkIT() { using (log4net.ThreadContext.Stacks[“NDC”].Push(GetMyMethodName())) { Log.Info(“Inside ” + GetMyMethodName() + ” Method.”); System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader(); //PrincipalContext AD = null; using (PrincipalContext AD = new PrincipalContext(ContextType.Domain, (string)reader.GetValue(“Domain”, typeof(string)))) { UserPrincipal u = new UserPrincipal(AD); u.Enabled = true; //u.Surname = “ju*”; using […]

UserPrincipal.FindByIdentity()始终返回null

我正在使用LdapAuthentication将用户登录到Active Directory。 我想找到用户所属的所有组。 我使用以下代码: string adPath = “LDAP://OU=HR Controlled Users,OU=All Users,DC=myDomain,DC=local”; LdapAuthentication adAuth = new LdapAuthentication(adPath); try { if (true == adAuth.IsAuthenticated(“myDomain”, txtLoginEmail.Text, txtLoginPassword.Text)) { string email = txtLoginEmail.Text; using (PrincipalContext context = new PrincipalContext(ContextType.Domain)) { UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.Name, email); foreach (var group in user.GetGroups()) { Console.WriteLine(group.Name); } } } } catch(Exception e) […]

使用PrincipalContext和ADLDS,LDAP服务器不可用

我们正在利用ADLDS进行用户管理和身份validation。 我们可以毫无问题地成功查询实例。 但是,如果未设置密码,尝试执行SetPassword等操作将失败甚至尝试创建新用户,则会失败。 我可以成功更新用户,只要它不是我想要更新的密码。 我一直在阅读很多与此相关的不同文章,但没有找到解决方案。 发帖看看我是否可以对这个问题有一些新的看法,感谢任何意见。 例 ContextType ctxType = ContextType.ApplicationDirectory; string server = “myadldsserver.com”; string usersCN = “CN=Users,…”; // container where users reside ContextOptions ctxOpts = ContextOptions.SimpleBind; string uname = “myuser”; string pswrd = “mypass”; using(var ctx = new PrincipalContext(ctxType, server, usersCN, ctxOpts, uname, pswrd) using(var newUser = new UserPrincipal(ctx)) { newUser.Name = “newusername”; […]

使用PrincipalContext.ValidateCredentials对本地计算机进行身份validation时出错?

我有一个WCF服务,其中包含一个Login方法,该方法根据本地计算机凭据validation用户名和密码,并且在看似随机的一段时间后,它将停止为某些用户工作。 实际的登录命令如下所示: public UserModel Login(string username, string password, string ipAddress) { // Verify valid parameters if (username == null || password == null) return null; try { using (var pContext = new PrincipalContext(ContextType.Machine)) { // Authenticate against local machine if (pContext.ValidateCredentials(username, password)) { // Authenticate user against database using (var context = new MyEntities(Connections.GetConnectionString())) { […]