C# – 如何使用DirectorySecurity.SetOwner()? 我遇到了麻烦
我在搞清楚SetOwner()
方法时遇到了麻烦。 在我的例子中,我通过代码在Active Directory中创建了一个用户,然后,我为用户创建了一个文件夹。
一切正常,但我不能将新创建的用户设置为文件夹的所有者。 我不是C#guru,所以我很难理解DirectorySecurity.SetOwner()
方法。 有人可以帮帮我吗?
这是创建文件夹的代码,设置我想要的权限,但我还需要将用户设置为所有者。
string pathIntern = @"\\11fil01\brukar\" + user.UserName; System.IO.DirectoryInfo diIntern = new System.IO.DirectoryInfo(pathIntern); diIntern.Create(); DirectorySecurity dsecIntern = diIntern.GetAccessControl(); FileSystemAccessRule rule = new FileSystemAccessRule(user.UserName, FileSystemRights.FullControl, InheritanceFlags.None | nheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow); dsecIntern.SetAccessRule(rule); diIntern.SetAccessControl(dsecIntern); //dsecIntern.SetOwner(heeeeelp);
试试这个
string pathIntern = @"\\11fil01\brukar\" + user.UserName; DirectoryInfo diIntern = new DirectoryInfo(pathIntern); DirectorySecurity dsecIntern = diIntern.GetAccessControl(); IdentityReference newUser = new NTAccount(domain + @”\” + username); dsecIntern.SetOwner(newUser); FileSystemAccessRule permissions = new FileSystemAccessRule(newUser,FileSystemRights.FullControl, AccessControlType.Allow); dsecIntern.AddAccessRule(permissions); diIntern.SetAccessControl(dsecIntern);
您也可以通过C#查看此链接创建,读取,更新Active Directory用户
再见。
- 哪个是性能最佳的:XPathNavigator与XPath vs Linq到Xml查询?
- 如何通过编程方式通过代理连接到TFS?
- 如何将PropertyInfo转换为属性表达式并使用它来调用generics方法?
- 限制集合仅检索只读实体的最近条目
- HttpModule – 获取HTML内容或控件以进行修改
- 如何获取调用方法的参数值?
- 在数据库中存储大型文件会导致类型为“System.OutOfMemoryException”的exception
- 避免使用C#中的Application.DoEvents()
- 在什么情况下调用Application_EndRequest但是没有调用Application_BeginRequest?