【问题标题】:Changing file permissions results in IdentityNotMappedException (when code is ran on web server)更改文件权限会导致 IdentityNotMappedException(在 Web 服务器上运行代码时)
【发布时间】:2011-11-16 08:51:18
【问题描述】:

我有以下代码 (from msdn) 来设置文件权限:

' Adds an ACL entry on the specified file for the specified account.
Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)

    ' Get a FileSecurity object that represents the 
    ' current security settings.
    Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

    ' Add the FileSystemAccessRule to the security settings. 
    Dim accessRule As FileSystemAccessRule = New FileSystemAccessRule(account, rights, controlType)

    fSecurity.AddAccessRule(accessRule)

    ' Set the new access settings.
    File.SetAccessControl(fileName, fSecurity)

End Sub

我使用IIS_IUSRS 组来调用它(我也尝试过ComputerName/IIS_IUSRS)并且我正在尝试申请FileSystemRights.FullControl

但是导致这个错误:

System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated

这表明 IIS_IUSRS 不存在(确实存在)。我的下一步是输出机器上的用户和组,看看我的代码认为确实存在什么。与此同时,有人知道为什么,或者是什么原因造成的吗?

此代码在我的本地机器上运行良好,但在我的网络服务器上运行时却不行。应用程序池作为网络服务运行,并且网络服务器对文件所在的文件夹具有完全权限。我注意到 this question 表明用户需要对目录的权限 - 但这不是问题。

【问题讨论】:

    标签: asp.net .net permissions file-permissions


    【解决方案1】:

    要解决此问题,请将网站上的身份验证更改为“与应用程序池相同”(而不是匿名)运行。不是最佳答案,但已尝试其他所有方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      • 2011-03-19
      • 2015-11-06
      • 2011-05-07
      • 1970-01-01
      相关资源
      最近更新 更多