2014-06-09 3 views
1

다음 코드 조각으로 IIS 서버에서 호스팅 된 웹 사이트를 가져 오는 방법을 만들었습니다. 내가 서버 시스템 (Windows server 2003 R2 with IIS 6)에서 실행할 때 내가 그것을 working.It이 어떤 도움이 가득 좋을 것IIS에서 호스트 된 웹 사이트 이름을 얻으려면

Retrieving the COM class factory for component with CLSID {2B> 52-803546CE3344} failed due to the following error: 80040154> d (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

오류 다음 준다의 IT 완벽 (Windows 7 /IIS 7 with 32bits) 나누었다을 일하고 내 로컬 컴퓨터에서 실행

 ServerManager serverManager = new ServerManager(); 

     try 
     { 
      foreach (Site site in serverManager.Sites) 
      { 
       Console.WriteLine(site); 
      } 

     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.Message); 

      Console.ReadLine(); 
     } 

?

답변

2

대 32 비트의 매우 가능성과 내 problem.It뿐만 아니라 IIS6 및 IIS7와 함께 작동합니다 해결했다.

public class IisManager 
    { 
     public static int IisVersion 
     { 
      get 
      { 
       int iisVersion; 

       using (RegistryKey iisKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\InetStp")) 
       { 
        if (iisKey == null) 
         throw new Exception("IIS is not installed."); 
        iisVersion = (int)iisKey.GetValue("MajorVersion"); 
       } 

       return iisVersion; 
      } 

     } 

     public static IList<IisWebSite> GetIisSites() 
     { 
      List<IisWebSite> sites = new List<IisWebSite>(); 

      using (DirectoryEntry iisRoot = new DirectoryEntry("IIS://localhost/W3SVC")) 
      { 
       iisRoot.RefreshCache(); 
       sites.AddRange(iisRoot.Children.Cast<DirectoryEntry>().Where(w => w.SchemaClassName.ToLower(CultureInfo.InvariantCulture) == "iiswebserver").Select(w => new IisWebSite(w.Name, w.Properties["ServerComment"].Value.ToString()))); 
      } 

      return sites; 
     } 

     public static IList<string> GetIisAppPools() 
     { 
      List<string> pools = new List<string>(); 
      using (DirectoryEntry poolRoot = new DirectoryEntry("IIS://localhost/W3SVC/AppPools")) 
      { 
       poolRoot.RefreshCache(); pools.AddRange(poolRoot.Children.Cast<DirectoryEntry>().Select(p => p.Name)); 
      } 
      return pools; 
     } 

    } 
1

이 블로그 게시물, 특히 마지막 단락을 확인하십시오. 그것은 내가 대신 Microsoft.Web.Administration를 사용 System.DirectoryServices를 사용한 64 비트 DLL 컴파일 충돌

Both the customer and I were creating 32-bit .NET applications, and the COM interface for the FTP runtime state is implemented in a 64-bit-only DLL. Once we both changed our projects to compile for 64-bit platforms, we were both able to get the code to run. (Coincidentally, all I had was a 32-bit system when I wrote my original blog, so I probably would have run into this sooner if I had owned a 64-bit system way back then. ;-])

http://blogs.iis.net/robert_mcmurray/archive/2012/06/29/error-class-not-registered-0x80040154-when-querying-ftp-runtime-state.aspx

관련 문제