文章出處

一、錯誤情況

環境:win7+iis7.0

DirectoryEntry配置IIS7出現如下錯誤

或者是

下面一段代碼在IIS6.0下運轉正常,但IIS7.0下運轉會出錯:

 

System.DirectoryServices.DirectoryEntry iisServer;
iisServer = 
new System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1");
System.DirectoryServices.
DirectoryEntry rootFolder = iisServer.Children.Find("Root","IIsWebVirtualDir");//此處拋出異常

異常內容如下: 

[System.Runtime.InteropServices.COMException] {"Unknown error (0x80005000)"} 
System.Runtime.InteropServices.COMException

Unknown error (0x80005000)
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_IsContainer()
   at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
   at System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName) 

 

二、錯誤分析

這段異常代碼表明 IIS://localhost/W3SVC/1 的ADSI provider不存在或者無法訪問。

打開IIS管理器你可以看到服務器的localhost(即默認站點)是存在的并正在運行,且主站點ID確實是1。這說明問題是出現在 IIS://localhost的ADSI provider。

 

三、錯誤原因

win7使用的是iis7,而IIS 7默認并沒有安裝ADSI provider。 

 

四、解決方法 

要解決這個問題就得安裝“IIS 元數據庫和IIS 6配置兼容性”。

“控制面板”->“程序和功能”->面板左側“打開或關閉windows功能”->“Internet信息服務”->“Web管理工具”->“IIS 6管理兼容性”->“IIS 元數據庫和IIS 6配置兼容性”。

如下圖所示:

 

 

五、更好的解決方法

更理想的解決方式是用 WMI provider操作IIS 7 ,可參見此篇文章http://msdn.microsoft.com/en-us/library/aa347459.aspx

 

六、Windows Server 2008出現這種錯誤怎么辦?

在Windows Server 2008下,使用角色服務安裝完“IIS 元數據庫和IIS 6配置兼容性”,還有可能出現如下錯誤:  

[System.Runtime.InteropServices.COMException] {"Access is denied.\r\n"} System.Runtime.InteropServices.COMException
ErrorCode 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.CheckIsContainer()
   at System.DirectoryServices.DirectoryEntries.Find(String name, String schemaClassName)

這是因為 Windows Server 2008被UAC(User Account Control,用戶賬戶控制)鎖定了.  你需要用管理員(Administrator)賬戶執行這個程序. 另一種方式是設置運行此程序的賬戶擁有如下權限: Logon as a Service"/ "Logon as a Batch Job"


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()