将安全组添加到文件夹问题/系统.安全最重要的IdentityNotMappedException:



我正在处理一个奇怪的问题,我想知道是否有人能帮我。在我的程序的某个时刻,我喜欢向文件夹添加具有适当权限的安全组。台阶看起来像那样。

  1. 创建文件夹
  2. 创建域本地安全组
  3. 创建全局安全组
  4. 将全局组添加到本地组
  5. 将域本地安全组添加到文件夹"\Domain\dfs\folder">

我从微软页面获得了以下代码

public static void AddDirectorySecurity(string DirectoryName, string Group, FileSystemRights Rights, InheritanceFlags iFlag, PropagationFlags pFlag, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);
// Get a DirectorySecurity object that represents the  
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings. 
dSecurity.AddAccessRule(new FileSystemAccessRule(Group,Rights,iFlag,pFlag,ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity); // 
}

添加过程如下:

path = @"\domaindfsfolder"
gRDL_RW = "RDL-group-RW"
AddDirectorySecurity(path, gRDL_RW, FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);

它在我的测试环境中运行良好,但当我喜欢在生产环境中运行它时,我会遇到错误:

************** Exception Text **************
System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
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 Program_dev_1.Form1.button1_Click(Object sender, EventArgs e) in  c:Users?????????DocumentsVisual Studio 2012Projectsbrite_dev_1brite_dev_1Form1.cs:line 191
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

这是"管理员权限"的问题吗?我在生产环境中拥有上帝般的权限。那到底发生了什么?

我觉得由于某种原因,所有那些用户友好的名称,如"FileSystemRights.Modify"都无法翻译。我在测试和生产环境中检查了区域设置,结果两者都是一样的。

有可能使用隐藏在这些用户友好名称后面的原始数字吗?

也许还有其他方法可以将安全组添加到文件夹中?我真正想要的只是一个有效的解决方案。

当尝试将组添加到文件夹时,应用程序正在崩溃,因为并非所有域控制器都立即知道新创建的组。在处理其余代码之前,我必须创建一个过程来检查新创建的组是否已在整个庄园中同步。这是不可能的,或者我找不到在将组添加到文件夹权限时使用的指定域控制器的方法。

最新更新