2015-02-10 53 views
5

我有一個控制檯應用程序,它使用Microsoft.Web.Administration來遠程管理遠程服務器上的IIS(我使用過這Credentials for ServerManager.OpenRemote - 修改了ahadmin屬性,打開TCP端口135.我也使用模擬)。一切工作正常 - 我可以遠程創建站點和應用程序池等。ServerManager.OpenRemote錯誤80040154 ASP.NET MVC 4中的CLSID {2b72133b-3f5b-4602-8952-803546ce3344}

但是,當我試圖做同樣的事情在ASP.NET MVC應用程序4,我得到這個錯誤:

System.Runtime.InteropServices.COMException: Retrieving the COM class factory for remote component with CLSID {2B72133B-3F5B-4602-8952-803546CE3344} from machine "remoteServerIP" failed due to the following error: 80040154 "remoteServerIP".

我知道很多人得到這個錯誤,我看到很多帖子關於它,但沒有爲我工作。我嘗試將我的MVC應用程序切換到平臺目標X86(Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154),在遠程計算機上,我啓用了HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ CLSID {2b72133b-3f5b-4602-8952-803546ce3344}和HKEY_CLASSES_ROOT \ CLSID {2b72133b-3f5b- 4602-8952-803546ce3344}爲我用來模擬的帳戶。 這個問題似乎是在MVC和控制檯應用程序之間的一些區別,但我無法弄清楚它是什麼。

我在Windows 7 x64,遠程服務器 - Windows Server 2008 R2 x64上。兩臺機器都有IIS 7.5。

回答

10

我找到了解決方案。問題在於我的MVC應用程序使用了錯誤版本的Microsoft.Web.Administration.dll。

當我在調試控制檯應用程序,我可以使用此代碼

ServerManager serverManager = new ServerManager(); 

,並使用此代碼

ServerManager serverManager = ServerManager.OpenRemote("remoteServerIpAddress"); 
從遠程IIS網站的列表,以獲得從本地IIS網站的列表

和一切都很好。 然後,我將完全相同的代碼放在MVC應用程序中,當我試圖從遠程IIS獲取網站列表時,我得到了該問題的異常。 當試圖從本地IIS獲取網站列表時,我從IIS Express獲取了網站。服務器管理器似乎連接到IIS Express,而不是完整的IIS,但我一開始並沒有太在意。不幸。

無意中我發現這個職位Microsoft.Web.Administration.ServerManager looking in wrong directory for IISExpress applicationHost.config,在那裏我發現

If the application, in which you are using Microsoft.Web.Administration ..., is running on IISExpress, it will always fallback to Microsoft.Web.Administration version 7.9.0.0 due to an assembly redirect in the aspnet.config in the IIS express.

我使用IIS Express來調試,它重定向我Microsoft.Web.Administration.dll的錯誤版本 - 7.9。 0.0,並且我需要7.0.0.0,它由完整的IIS使用。 因此,我在完整的本地IIS上託管了我的MVC應用程序,並在那裏進行了調試,並且工作正常!我成功地從遠程IIS檢索了一個站點列表。希望它能幫助別人。

+0

OMG非常感謝你!這讓我瘋狂! – 2016-06-28 21:18:03

+0

同樣的問題,但與.net核心microsoft.web.administration包認爲它是正確的使用 – Ewan 2018-02-23 12:23:36

相關問題