簡體   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