2013-01-15 67 views
4

我有一個控制檯應用程序,列表網站在IIS結合的DirectoryEntry IIS訪問權限

using (var directoryEntry = new DirectoryEntry("IIS://localhost/w3svc/" + GetWebSiteId())) { 
    var bindings = directoryEntry.Properties["ServerBindings"]; 
} 

我通過過程調用這個控制檯應用程序從ASP.NET

var process = new Process { 
    StartInfo = new ProcessStartInfo { 
     FileName = "c:/app.exe", 
     Arguments = "check", 
     UseShellExecute = false, 
     RedirectStandardOutput = true, 
     CreateNoWindow = true 
    } 
}; 

下,一切工作正常開發機器上Widows 7/IIS 7.5,但是當我在Windows 2012/IIS 8上測試時出現「Access is denied」錯誤。

錯誤日誌

"System.Runtime.InteropServices.COMException (0x80070005): Access is denied. 
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) 
at System.DirectoryServices.DirectoryEntry.Bind() 
at System.DirectoryServices.DirectoryEntry.get_IsContainer() 
at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container) 
at System.DirectoryServices.DirectoryEntries.GetEnumerator() 
at IISSubdomainManagement.Program.GetWebSiteId() 
at IISSubdomainManagement.Program.TotalBindings() 
at IISSubdomainManagement.Program.Main(String[] args)" 

PS應用程序池標識爲 「ApplicationPoolIdentity」


我忘記說了,我的控制檯應用程序正常工作我的服務器上,當我從CMD

+0

我已經收到了這一個,如果我還記得,這個問題是要麼在那裏尋找AD服務器或憑據別沒有正確的權限。這很煩人,因爲它在本地工作正常 – Brian

回答

2
運行

您需要授予IUSR帳戶權限才能訪問並執行C:\app.exeThis link應該爲您提供必要的信息以找到正確的帳戶。

+1

IUSR和IIS_IUSRS具有完整的app.exe安全控制,但仍然不工作 –

+0

我可以確認當IIS_IUSRS沒有訪問時得到的COMException是System.DirectoryServices.DirectoryServicesCOMException(0x80072020) :發生操作錯誤.'(而不是'訪問被拒絕') – codeMonkey

1

您可能已授予「ApplicationPoolIdentity」權限,而不授予實際與該應用程序池對應的虛擬帳戶。通讀Microsoft's description或在線搜索虛擬身份IIS等。

在您的開發機器上,您可能擁有某種完全管理權限,因此它不受限制。

如果之後仍然存在問題,我建議您將錯誤複製到Process Monitor正在運行,以便您可以確切瞭解哪個進程正在訪問哪個資源具有哪個身份。但是,我建議在開發機器上覆制問題,而不是在生產環境中運行Process Monitor。它需要一點點的學習才能夠有效地運行它。

+0

完成後,我將我的應用程序池創建的虛擬身份添加爲app.exe的完全安全權限,但仍然出現錯誤... –

+0

當我選擇「LocalSystem」作爲應用程序池標識,一切正常,但爲什麼我不能作爲ApplicationPoolIdentity –

+0

LocalSystem是一個真實身份,一個是特例。我更新了主要評論,並提供了關於下一步故障排除的其他建議。 –

1

在IIS 7/8去控制面板 /程序和功能/啓用Windows功能打開或關閉,並檢查所有項目來源:網絡梟雄工具,(它的包括:IIS梟雄服務,II 6梟雄兼容性)