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);
上一篇:02-CSS基础与进阶-day11_2018-09-17-20-55-43


下一篇:移动端CSS样式----笔记