如何在.net中将SID转换为字符串

编程入门 行业动态 更新时间:2024-10-27 10:28:57
本文介绍了如何在中将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转换为字符串

本文发布于:2023-11-09 15:18:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   中将   如何在   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!