c# – NTAccount.Translate方法失败并显示错误无法转换部分或全部标识引用
作者:互联网
PipeAccessRule par = new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
此代码失败并显示错误:
Some or all identity references could not be translated.
我想这是因为我在非英语本地启动我的应用程序时使用“Everyone”.在英语系统上一切都很好.
怎么避免这个?是否有一些enum描述了一般用户组?
堆栈跟踪:
at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.NTAccount.Translate(Type targetType)
at System.Security.AccessControl.CommonObjectSecurity.ModifyAccess(AccessControlModification modification, AccessRule rule, Boolean& modified)
at System.Security.AccessControl.CommonObjectSecurity.AddAccessRule(AccessRule rule)
at System.IO.Pipes.PipeSecurity.AddAccessRule(PipeAccessRule rule)
解决方法:
通过使用PipeAccessRule和SecurityIdentifier的第二个构造函数而不是字符串解决:
System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
PipeAccessRule par = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
标签:c,net,user-accounts,translate 来源: https://codeday.me/bug/20190613/1232534.html