2
我有以下代碼(from msdn)設置文件權限:更改文件權限導致IdentityNotMappedException(當代碼的Web服務器上運行)
' 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不存在(它確實)。我的下一步是輸出機器上的用戶和組,以查看我的代碼認爲是否存在。同時,有沒有人知道爲什麼,或者是什麼原因造成的?
此代碼在本地機器上正常工作,但在我的Web服務器上運行時無法正常工作。應用程序池作爲網絡服務運行,Network Server對文件所在的文件夾具有FULL權限。我注意到this question表明用戶需要目錄權限 - 但這不是問題。