本文介绍了如何在中将SID转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将SID的System.Byte []类型转换为字符串.
I would like to convert the SID's System.Byte[] type to a String.
我的代码:
string path = "LDAP://DC=abc,DC=contoso,DC=com"; DirectoryEntry entry = new DirectoryEntry(path); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = "(&(objectClass=user)(samaccountname=user1))"; results = mySearcher.FindAll(); foreach (SearchResult searchResult in results) { Console.WriteLine(searchResult.Properties["ObjectSID"][0].ToString()); }我尝试过此操作,但它从当前登录的域中获取值,而我需要从给定的域中获取值.
I tried with this but it gets the values from the domain I'm currently logged in, and i need from a given domain.
System.Security.Principal.NTAccount(user1) .Translate([System.Security.Principal.SecurityIdentifier]).value 推荐答案看看 SecurityIdentifier 类.然后,您可以做一些简单的事情,
Take a look at the SecurityIdentifier class. You can then do simple things like,
var sidInBytes = (byte[]) *somestuff* var sid = new SecurityIdentifier(sidInBytes, 0); // This gives you what you want sid.ToString();更多推荐
如何在.net中将SID转换为字符串
发布评论