文件夹权限 – 无法翻译部分或全部身份参考
我想在远程服务器上为域用户设置文件夹ACL,但始终会出现以下错误消息:
无法翻译部分或全部身份参考
我究竟做错了什么?
这是我的代码:
string folderPath = @"\\remoteServer\testDirectory" string accountName = "domainUser" string domainName = "mydomain"; accountName = domainName + "\\" + accountName; //What rights are we setting? //set on dir itself FileSystemAccessRule accessRule = new FileSystemAccessRule(accountName, FileSystemRights.FullControl, AccessControlType.Allow); DirectoryInfo dInfo = new DirectoryInfo(folderPath); DirectorySecurity dSecurity = dInfo.GetAccessControl(); //dInfo.SetAccessControl(dSecurity); dSecurity.AddAccessRule(accessRule);`
如果我只输入userName
而不是domainname\username
则会设置权限但使用“unknown account”
有人可以请帮忙……
提前致谢。
我找到了解决这个问题的方法。 必须创建使用您要允许的用户的SID创建的SecurityIdentifier对象。 查看我的解决方案代码
来自Blen的链接:
// Get User from AD with System.DirectoryServices.AccountManagement; UserPrincipal user = GetPrinicpalBySamAccountName ( "userSamAccount" ); string usersid = user.Sid.ToString (); SecurityIdentifier secIdentifierSid = new SecurityIdentifier ( usersid ); FileSystemAccessRule AccessRule = new FileSystemAccessRule ( secIdentifierSid , FileSystemRights.Full Control , Access Control Type . Allow );
我将其更改为使用我们创建的SecurityIdentifier而不是简单地发送SID。 这似乎有效。