繁体   English   中英

目录服务返回奇怪的字符

[英]Directory Services Returns Strange Characters

目前,我们有一个SQL Server视图,该视图查询AD并返回有关所有组的信息。

SELECT  ADsPath, cn, mail, displayname
FROM    OPENQUERY(ADSI, 'SELECT ADsPath, cn,mail,displayname  
                         FROM    ''LDAP://DC=mycompany,DC=co,dc=uk'' 
                         WHERE   objectCategory=''group''    ') AS Rowset_1

组ADsPath值中的某些包含-字符,例如LDAP:// CN = EXCHANGE – CARGO,CN = Users,DC = mycompany,DC = co,DC = uk

我现在使用C#和DirectoryServices替换此SQL Server视图,如下所示:

public List<AdGroup> GetGroups()
{
    var groupMembers = new List<AdGroup>();
    using (var ds = new DirectorySearcher(_ldap))
    {
        ds.Filter = String.Format("(&(objectCategory=group))");
        ds.PageSize = 5000;

        ds.PropertiesToLoad.Add("ADsPath");
        ds.PropertiesToLoad.Add("cn");
        ds.PropertiesToLoad.Add("mail");
        ds.PropertiesToLoad.Add("displayName");
        using (var results = ds.FindAll())
        {
            foreach (SearchResult sr in results)
            {                        
                string adsPath = string.Empty;
                if (sr.Properties.Contains("ADsPath"))
                    adsPath = sr.Properties["ADsPath"][0].ToString();

                string cn = string.Empty;
                if (sr.Properties.Contains("cn"))
                    cn = sr.Properties["cn"][0].ToString();

                string mail = string.Empty;
                if (sr.Properties.Contains("mail"))
                    mail = sr.Properties["mail"][0].ToString();

                string displayName = string.Empty;
                if (sr.Properties.Contains("displayName"))
                    displayName = sr.Properties["displayName"][0].ToString();

                DirectoryEntry userAccount = new DirectoryEntry(adsPath);
                string objectGUID = userAccount.Guid.ToString();

                groupMembers.Add(new AdGroup(adsPath, objectGUID, cn, mail, displayName));

            }
        }
        return groupMembers;
    }
}

问题是DirectoryServices将-字符返回为–

我需要怎么做才能使DirectoryServices将-字符返回为-

而不是作为–

谢谢您的帮助。

我正在将检索到的广告信息写入文本文件,以便检查结果。 将信息保存在文本文件中会将所有文本转换为ASCII格式,并导致显示奇怪的字符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM