您的位置:首页 > 编程语言 > C#

[C#]解决多语言操作系统找不到everyone NTAccount问题

2012-11-26 11:13 288 查看
NTAccount acct = new NTAccount("Everyone");
FileSystemAccessRule allowRule = new FileSystemAccessRule(acct, FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow);


这两行代码运行在英文系统下一切正常,但如果在多语言(如葡萄牙、瑞典、芬兰)系统下则会引发异常,异常信息如:

The conversion of some or all identifying references has failed或

Some or all identity references could not be translated.

也就是在多语言系统找不到对应的“Everyone” NTAccount,那问题自然就转移到如何才能在多语言系统找到匹配的“everyone”呢?这得感谢该帖子:http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/0737f978-a998-453d-9a6a-c348285d7ea3/

直接找到答案了,代码调整如下:

SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
NTAccount acct = sid.Translate(typeof(NTAccount)) as NTAccount;

FileSystemAccessRule allowRule = new FileSystemAccessRule(acct, FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow);


WellKnownSidType.WorldSid的Summary是:Indicates a SID that matches everyone.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐