C# 将安全组添加到文件夹issue/System.security.Principal.IdentityNotMappedException:

C# 将安全组添加到文件夹issue/System.security.Principal.IdentityNotMappedException:,c#,security,directory,system.security,C#,Security,Directory,System.security,我正在为一个奇怪的问题而挣扎,不知是否有人能帮助我。 在我的程序中,我喜欢在文件夹中添加具有适当权限的安全组。步骤是这样的 创建文件夹 创建域本地安全组 创建全局安全组 将全局组添加到本地组 将域本地安全组添加到文件夹“\Domain\dfs\folder” 我从微软网页上得到了下面的一段代码 public static void AddDirectorySecurity(string DirectoryName, string Group, FileSystemRights Rights,

我正在为一个奇怪的问题而挣扎,不知是否有人能帮助我。 在我的程序中,我喜欢在文件夹中添加具有适当权限的安全组。步骤是这样的

  • 创建文件夹
  • 创建域本地安全组
  • 创建全局安全组
  • 将全局组添加到本地组
  • 将域本地安全组添加到文件夹“\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 = @"\\domain\dfs\folder"
    
    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\?????????\Documents\Visual Studio 2012\Projects\brite_dev_1\brite_dev_1\Form1.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”都无法翻译。我在test和prod环境中检查locale,两者都是相同的

    是否可以使用隐藏在用户友好名称后面的原始数字


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

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

    与论坛网站不同,我们不使用“感谢”或“感谢任何帮助”或签名。见”。