如何在.net中将SID转换为字符串 [英] How to convert SID to String in .net

查看:55
本文介绍了如何在.net中将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

推荐答案

看看

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转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆