【发布时间】: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