0

奇怪的是,在本地主机上托管时,我可以从服务器获取 AD 列表,但是当在服务器 2008 R2 上托管时,它返回错误,我使用的是 LinqToLDAP,知道实际出了什么问题吗?

            var config = new LdapConfiguration();
            config.ConfigureFactory(Server).ProtocolVersion(3);
            config.MaxPageSizeIs(Size);

            using (HostingEnvironment.Impersonate()) //solved issue for firefox and safari
            {
                using (var context = new DirectoryContext(config))
                {
                    context.Log = Console.Out;
                    var user = context.Query<ActiveDirectory>();

                    var result = (from m in user
                                  select m).ToList();
                    return result;
                }
            }

在此处输入图像描述

4

2 回答 2

0

好的,找到了答案,通过谷歌搜索并玩了一下代码后,发现我需要传递网络凭据才能使其工作

于 2013-09-03T07:44:17.907 回答
0

这是在我当前系统中运行良好的代码,请随时学习

网络配置

<add key="LdapServer" value="yourADserverName" />
<add key="LdapSize" value="totalpagesziereturn" />
<add key="CreName" value="yourdomainuserid" />
<add key="CrePass" value="yourpassword" />
<add key="CreDomain" value="yourdomain" />

AD.cs

    private int Size = Convert.ToInt32(ConfigurationManager.AppSettings["LdapSize"]);
    private string Server = ConfigurationManager.AppSettings["LdapServer"];
    private NetworkCredential UserCredential = new NetworkCredential(ConfigurationManager.AppSettings["CreName"], ConfigurationManager.AppSettings["CrePass"], ConfigurationManager.AppSettings["CreDomain"]);

    /// <summary>
    /// Get all user from active directory
    /// </summary>
    /// <returns></returns>
    public IEnumerable<ActiveDirectory> GetActiveDirectory()
    {
        var config = new LdapConfiguration();
        config.ConfigureFactory(Server).ProtocolVersion(3).UsePort(389).AuthenticateAs(UserCredential);
        config.MaxPageSizeIs(Size);

        using (HostingEnvironment.Impersonate()) //solved issue for firefox and safari
        {
            using (var context = new DirectoryContext(config))
            {
                context.Log = Console.Out;
                var user = context.Query<ActiveDirectory>();

                var result = (from m in user
                              select m).ToList();
                return result;
            }
        }
    }
于 2014-02-22T00:30:23.023 回答