[英]DirectoryEntry IIS access permission
我有一個控制台應用程序,它列出了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上測試時,我得到“訪問被拒絕”錯誤。
錯誤日志
"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運行它時,我的控制台應用程序在我的服務器上工作正常
您需要授予IUSR帳戶權限才能訪問和執行C:\\app.exe
。 此鏈接應為您提供查找正確帳戶所需的信息。
您可能已授予“ApplicationPoolIdentity”權限,而不是實際對應於該應用程序池的虛擬帳戶。 閱讀Microsoft的說明或在線搜索虛擬身份IIS等。
在您的開發計算機上,您可能擁有某種完全管理員權限,因此它不受限制。
如果之后仍有問題,我建議在運行Process Monitor的情況下復制錯誤,這樣您就可以確切地看到哪個進程正在訪問哪個資源具有哪個標識。 但是,我建議在開發計算機上復制該問題,而不是在生產中運行Process Monitor。 需要一點點學習才能有效地運行它。
在IIS 7/8中,打開或關閉控制面板 /程序和功能/打開Windows功能,並檢查所有項目 :Web管理工具,(包括:IIS管理服務,II 6管理兼容性)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.