2016-04-25 36 views
1

私はUserPrincipalを返しますが、loginnameにdomainnameを含めないでください。プロパティ "Domainname"などはありません。UserPrincipalまたはPrincipalSearcherからドメイン名を取得する方法

UserPrincipalまたはPrincipalSearcherからドメインをユーザー/返されたユーザーに取得するにはどうすればよいですか?

PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 
    UserPrincipal user = new UserPrincipal(ctx); 
    user.SamAccountName = txtSearch.Text; 
    PrincipalSearcher searcher = new PrincipalSearcher(user); 

    PrincipalSearchResult<Principal> results = searcher.FindAll(); 
    foreach (UserPrincipal u in results) 
    { 
     Response.Write(u.Name + "<br />"); 
    } 
+0

この質問は次のとおりです。http://stackoverflow.com/questions/10702188/where-is-the-domain-name-in-a-userprincipal-objectは似ていますが、受け入れられない回答があります。http:// stackoverflow.com/questions/4284641/get-netbiosname-from-a-userprincipal-object –

答えて

3

これはdomain\userを返し

usercontext.Sid.Translate(typeof(NTAccount)).ToString(); 

を使用して私のために働きました。

関連する問題