【发布时间】:2013-12-28 23:19:57
【问题描述】:
我正在为一个奇怪的问题而苦苦挣扎,我想知道是否有人可以帮助我。 在我的程序的某个时刻,我喜欢向文件夹添加具有适当权限的安全组。步骤看起来像这样。
- 创建文件夹
- 创建域本地安全组
- 创建全局安全组
- 将全局组添加到本地组
- 将域本地安全组添加到文件夹“\domain\dfs\folder”
我从 Microsoft 页面获得了以下代码来执行此操作
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”)都无法翻译。我检查了测试和生产环境的语言环境,两者都是一样的。
是否可以使用隐藏在这些用户友好名称后面的原始数字?
也许还有其他方法可以将安全组添加到文件夹?我真正喜欢的只是一个可行的解决方案。
【问题讨论】:
-
与论坛网站不同,我们不使用“谢谢”、“任何帮助表示赞赏”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?.
标签: c# security directory system.security