【问题标题】:How to get access control of C:\Windows\System32\inetsrv\config folder using c# asp.net如何使用 c# asp.net 获得对 C:\Windows\System32\inetsrv\config 文件夹的访问控制
【发布时间】:2017-12-28 05:03:00
【问题描述】:

我正在尝试授予 C:\Windows\System32\inetsrv\config 文件夹的权限。但是当我使用下面的代码时,它会抛出异常“尝试执行未经授权的操作”。

 string desktopFolderPath = @"C:\Windows\System32\inetsrv\config";

        FileSystemAccessRule iis_iusrs = new FileSystemAccessRule("IIS_IUSRS",
           FileSystemRights.FullControl,
           InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
           PropagationFlags.None,
           AccessControlType.Allow);

        FileSystemAccessRule networkService = new FileSystemAccessRule("NETWORK SERVICE",
            FileSystemRights.FullControl,
            InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
            PropagationFlags.None,
            AccessControlType.Allow);

        System.IO.DirectoryInfo desktopFolderDirectory = new System.IO.DirectoryInfo(desktopFolderPath);
        DirectorySecurity directorySecurity = null;

directorySecurity = desktopFolderDirectory.GetAccessControl(); -- **Exception**
            directorySecurity.AddAccessRule(iis_iusrs);
            directorySecurity.AddAccessRule(networkService);
            desktopFolderDirectory.SetAccessControl(directorySecurity);

如果有人可以,请提供帮助。提前致谢。

【问题讨论】:

  • 您是否以管理员用户身份执行代码?
  • 为什么要从您的 asp.net 站点访问 Windows 级别的文件?
  • @Jim 我想在客户端机器上运行这段代码,所以我不是管理员用户,但我想执行这些操作。我该怎么做?
  • @programtreasures 这与我之前的问题有关,即回收应用程序池。但为此我需要授予 IIS_IUSRS 权限,所以我需要访问客户端的配置文件夹来执行此操作。

标签: c# asp.net


【解决方案1】:

转到文件夹路径Properties 并确保未选中只读复选框。

这可能会有所帮助:link

如果没有,请尝试共享文件夹。

顺便说一下,它是系统文件夹,可能无法访问,所以尝试在C:\inetpub托管页面

【讨论】:

  • 好的,试试看这个:link - 它可能会有所帮助
猜你喜欢
  • 2012-08-31
  • 1970-01-01
  • 2019-05-26
  • 2011-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-01
  • 1970-01-01
相关资源
最近更新 更多