c# - .NET 中安全身份的本地化

标签 c# .net windows security sid

我正在寻找在 .NET 中为服务/客户端通信实现命名管道并遇到了 this code也就是说,在初始化管道的服务器端时,必须为管道设置一个安全描述符。他们是这样做的:

PipeSecurity pipeSecurity = new PipeSecurity();

// Allow Everyone read and write access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule("Authenticated Users",
    PipeAccessRights.ReadWrite, AccessControlType.Allow));

// Allow the Administrators group full access to the pipe.
pipeSecurity.SetAccessRule(new PipeAccessRule("Administrators",
    PipeAccessRights.FullControl, AccessControlType.Allow));

但我正在查看它,我担心将 SID 指定为字符串,或 Authenticated UsersAdministrators 部分。有什么保证可以用中文或其他语言来调用它们?

最佳答案

您可以使用 WellKnownSidType 枚举来获取 sid 并转换为 IdentityReference:

        var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
        var everyone = sid.Translate(typeof(NTAccount));
        security.AddAccessRule(new PipeAccessRule(everyone, PipeAccessRights.ReadWrite, AccessControlType.Allow));

关于c# - .NET 中安全身份的本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15890860/

相关文章:

c# - 检查值是否是 C# 中一组值中的一个的最简单方法?

.net - 如何检测系统时间是否更改? (来自.net)

windows - 批量高级防火墙异常(exception)(任何方向)

windows - Go中终止进程的跨平台方式

c# - 在 SL ComboBox 上使用 CollectionView 刷新时 SelectedItemIndex 不匹配

windows - 在 Mac OS X 上运行的虚拟机 : how to emulate Alt-F4?

c# - 从 c# expando 对象动态读取属性

c# - 从 C# 运行 Bash 命令

c# - 实现接口(interface)包括 throw new NotImplementedException ... 为什么?

.net - 如何提高 XML 读写性能