简体   繁体   English

如何使用c#asp.net获取C:\\ Windows \\ System32 \\ inetsrv \\ config文件夹的访问控制

[英]How to get access control of C:\Windows\System32\inetsrv\config folder using c# asp.net

I am trying to give permission to C:\\Windows\\System32\\inetsrv\\config folder. 我正在尝试授予C:\\ Windows \\ System32 \\ inetsrv \\ config文件夹的权限。 But when I use the below code it throws exception "Attempted to perform an unauthorized operation." 但是,当我使用以下代码时,它将引发异常“尝试执行未经授权的操作”。

 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);

Please help if anyone can. 如果有人可以,请帮忙。 Thanks in advance. 提前致谢。

Go to the folder path Properties and make sure it Read-only check box is unchecked. 转到文件夹路径“ Properties ,并确保未选中“只读”复选框。 inetsrv属性

This may be of some help: link 这可能会有所帮助: 链接

If it doesn't, then try sharing the folder. 如果没有,请尝试共享文件夹。

By the way it is a system folder, It may not be accessible, so try hosting pages in C:\\inetpub 顺便说一句,它是系统文件夹,可能无法访问,因此请尝试在C:\\inetpub托管页面

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 访问路径 'c:\windows\system32\inetsrv\config\' 被拒绝 - Access to the path 'c:\windows\system32\inetsrv\config\' is denied ASP零:System.IO.FileNotFoundException:找不到文件'c:\\ windows \\ system32 \\ inetsrv \\ log4net.config' - ASP Zero :System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\log4net.config' 如何在 C# 中获取 Windows\system32\config\systemprofile\AppData\Local\ 文件夹路径? - How to get Windows\system32\config\systemprofile\AppData\Local\ folder path in C#? WebClient下载-“拒绝访问路径'c:\\\\ windows \\\\ system32 \\\\ inetsrv \\\\ MyPrintManager.exe'” - WebClient Download - “Access to the path 'c:\\windows\\system32\\inetsrv\\MyPrintManager.exe' is denied” 在C#中访问System32 \\ config \\ SYSTEM配置单元 - Access System32\config\SYSTEM hive in C# 找不到文件 'c:\\windows\\system32\\inetsrv\\xxx.xlsx' - Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx' 收到 DirectoryNotFoundException: c:\\windows\\system32\\inetsrv\\Static_Files 当应用程序移动到实时服务器时 - Received a DirectoryNotFoundException: c:\windows\system32\inetsrv\Static_Files When application was moved to a live server 如何通过C#语言删除Windows 7 dll文件(在System32文件夹中) - How Delete A Windows 7 dll File (In System32 Folder) By C# Language 如何在C#中更改System32中文件夹的权限? - How to change permissions of a folder inside System32 in C#? .Net MVC 4 项目失败并显示事件日志错误“模块 DLL C:\\WINDOWS\\system32\\inetsrv\\aspnetcore.dll 无法加载。 数据就是错误。” - .Net MVC 4 Project fails with Event Log Error “The Module DLL C:\WINDOWS\system32\inetsrv\aspnetcore.dll failed to load. The data is the error.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM