建立上下文时如何设置连接超时-PrincipalContext [英] How to set connection time out when establishing context - PrincipalContext

查看:179
本文介绍了建立上下文时如何设置连接超时-PrincipalContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Domain, UserName, Password))
            {
                UserPrincipal U = new UserPrincipal(ctx);
                U.GivenName = strFirstName;
                U.Surname = strLastName;
                U.EmailAddress = strEmail;

                PrincipalSearcher srch = new PrincipalSearcher(U);

                foreach (var principal in srch.FindAll())
                {
                    var p = (UserPrincipal)principal;
                    if (!User.Any(x => x.Email == p.EmailAddress))
                    {
                        MyUserDataset.UserRow User = User.NewUserRow();
                        User.FirstName = p.GivenName;
                        User.LastName = p.Surname;
                        User.UserName = p.SamAccountName;
                        User.Email = p.EmailAddress;
                        User.AddUserRow(User);
                    }
                }
                User.AcceptChanges();
            }

我正在使用上面的PrincipalContext类建立与目标目录的连接并指定对目录执行操作的凭据。

I'm using the PrincipalContext class above to establish a connection to the target directory and specify credentials for performing operations against the directory.

有人知道我也可以在PrincipalContext构造函数中指定连接超时吗,我遇到了连接问题超时问题和我想知道我是否可以控制连接可以超时多长时间。

Does any one know how i can also specify the connection time out in the PrincipalContext Constructor?, i'm running into connection time out issues & i was wondering if i can control after how long the connection can time out.

推荐答案

好吧,我想答案很不幸。我已经研究了PrincipalContext的源代码,它使用DirectoryEntry,后者使用不安全的本机方法System.DirectoryServices.Interop.UnsafeNativeMethods.ADsOpenObject打开LDAP连接。

Well, I guess the answer is no unfortunately. I have dig into the source code of PrincipalContext, it used DirectoryEntry which used unsafe native method System.DirectoryServices.Interop.UnsafeNativeMethods.ADsOpenObject to open LDAP connection.

根据此博客: http://blogs.msdn.com/b/dsadsi/archive/2012/06/06/how-to-specify -timeout-for-ldap-bind-in-net.aspx ,无法在ADsOpenObject上配置超时。但是,它也提到如果直接使用LdapConnection,则可以设置超时。在这种情况下,您可能无法使用PrincipalContext。

As per this blog: http://blogs.msdn.com/b/dsadsi/archive/2012/06/06/how-to-specify-timeout-for-ldap-bind-in-net.aspx, there is no way to configure the timeout on ADsOpenObject. However, it also mentioned that if using LdapConnection directly, then it is possible to set the timeout. In that case, you may not be able to user PrincipalContext.

这篇关于建立上下文时如何设置连接超时-PrincipalContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆