小编Mar*_*p51的帖子

C#代码自动授予对Windows Server 2008上的文件夹的IIS写入权限?目前抛出异常

我正在尝试编写一个命令行工具,它将在Windows Server 2008上为IIS7.5提供对wwwroot中文件夹的写访问权限,以便Web应用程序可以访问其基本目录中的特定文件夹.以前,您可以通过在给予该组修改访问权限的文件夹上分配IIS_WPG组来执行此操作.

在Server 2008中,我正在尝试使用IIS_IUSRS执行相同的操作,但是例外情况正在发生.

这是代码:

private static void ManagePermissions(string directory, string account, FileSystemRights rights, AccessControlType controlType, bool addAccess)
{
    DirectoryInfo directoryInfo = new DirectoryInfo(directory);
    DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();

    if (addAccess)
        directorySecurity.AddAccessRule(
            new FileSystemAccessRule(account, rights, controlType));
    else
        directorySecurity.RemoveAccessRule(
            new FileSystemAccessRule(account, rights, controlType));

    directoryInfo.SetAccessControl(directorySecurity);
}
Run Code Online (Sandbox Code Playgroud)

对此方法的调用如下:

ManagePermissions(
                  "c:\inetpub\wwwroot", 
                  "MACHINENAME\IIS_IUSRS", 
                  FileSystemRights.Modify, 
                  AccessControlType.Allow, 
                  true);
Run Code Online (Sandbox Code Playgroud)

当执行对ManagePermissions的调用时,将引发具有以下类型和消息的异常:

System.Security.Principal.IdentityNotMappedException: 
    Some or all identity references could not be translated.
Run Code Online (Sandbox Code Playgroud)

我已多次检查以确保MACHINENAME\IIS_IUSRS与此代码正在执行的计算机上的本地用户管理器中的用户完全匹配.本机不参与Windows域.

如果您需要进一步澄清,请与我们联系.

c# ntfs windows-server-2008 iis-7.5

5
推荐指数
1
解决办法
3784
查看次数

标签 统计

c# ×1

iis-7.5 ×1

ntfs ×1

windows-server-2008 ×1