2009-03-11 3 views
1

C#에서 사용하는 IIS 가상 디렉터리의 .NET 프레임 워크를 어떻게 확인할 수 있습니까? 나는 그것을 사용자에게 보여줄 필요가있다.C#을 사용하여 가상 디렉터리 또는 웹 사이트의 ASP.NET 버전을 확인하려면 어떻게합니까?

using System.DirectoryServices; 
using System.IO; 

private enum IISVersion 
{ 
    IIS5, 
    IIS6 
} 

private void ReadVirtualDirectory(string server, string directory, IISVersion version) 
{ 
    string siteID = string.Empty; 
    string path = string.Empty; 

    switch(verison) 
    { 
     case IISVersion.IIS5: 
      path = string.Format("IIS://{0}/W3SVC/1/Root", server); 

      if(!string.IsNullOrEmpty(directory)) 
      { 
       path = string.Concat(path, "/", directory); 
      } 

      break; 

     case IISVersion.IIS6: 
      path = string.Format("IIS://{0}/W3SVC", server); 

      if(!string.IsNullOrEmpty(directory)) 
      { 
       DirectoryEntry de = new DirectoryEntry(path); 

       foreach(DirectoryEntry child in de.Children) 
       { 
        if(child.Properties["ServerComment"].Value.ToString().ToLower() == directory) 
        { 
         siteID = child.Name; 
         break; 
        } 
       } 

       path = string.Concat(path, "/", siteID); 

       de.Close() 
       de = null; 
      } 

      break; 
    } 

    DirectoryEntry iis = new DirectoryEntry(path); 

    //display iis properties here... 
    //need to display if the virtual directory is running under .NET 1.1 or 2.0 

    iis.Close(); 
    iis = null;  
} 
+0

멋진 코드입니다. 그것은 무엇을 올바르게합니까? 그것은 무엇을 잘못합니까? 당신이 묻는 질문에 대답하지 않습니까? 그렇지 않다면 왜 안 되겠습니까? –

+0

당신은 .NET Framework 또는 IIS의 어떤 버전을 알고 싶습니까? – RSolberg

+0

.NET Framework에 대해 알고 싶습니다. –

답변

5

는 웹 사이트에서 사용 또는 '가상'디렉토리 (웹 사이트 응용 프로그램 폴더되는 ASP.NET 버전을 확인 할 단단하고 빠른 방법이 없다 - 사람 아이콘으로 톱니가 있음).

이 이유는 IIS와 메타베이스 데이터가 모든 ASP.NET이 단지 다른 ISAPI 응용 프로그램 인 후에 ASP.NET 버전이 아니라 스크립트 맵에 대해서만 알고 있기 때문입니다.

using System; 
using System.DirectoryServices; 
namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string path = @"IIS://Localhost/W3SVC/1/root/MyApp"; 
      Console.WriteLine(GetAspNetVersion(path)); 
     } 

     private static string GetAspNetVersion(string path) 
     { 
      using (DirectoryEntry app = new DirectoryEntry(path)) 
      { 
       PropertyValueCollection pvc = app.Properties["ScriptMaps"]; 

       foreach (string scriptMap in pvc) 
       { 
        if (scriptMap.StartsWith(".aspx")) 
        { 
         string[] mapping = scriptMap.Split(','); 
         string scriptProcessor = mapping[1]; 

         // The version numbers come from the path 
         // C:\Windows\Microsoft.NET\Framework\ 
         // which will be present in the script processor 
         // DLL path 
         if (scriptProcessor.Contains("v1.1.4322")) 
         { 
          return "1.1"; 
         } 

         if (scriptProcessor.Contains("v2.0.50727")) 
         { 
          return "2.0"; 
         } 
        } 
       } 
       throw new Exception("Unknown version ASP.NET version."); 
      } 
     } 
    } 
} 

이상적 아니지만 우리의 프로비저닝 애플리케이션/서비스에 대한 호스팅으로 우리의 요구를 실패하지 않은 : ASP.NET의 버전을 확인하는 한 가지 방법은 다음과 같은 것을 사용하는 것입니다. 나는 IIS MMC 플러그 인이 뒤에서 비슷한 검사를 수행하는 것으로 의심합니다. 메타베이스 (Windows 2000 및 Windows 2003 파일 기반 XML)에 대한 자세한 내용은 특정 ASP.NET 버전 번호를 저장하는 눈에 띄는 속성/특성이 없음을 보여줍니다.

+0

해결책 주셔서 감사합니다. 웹 사이트의 각 가상 디렉터리에 대한 프레임 워크 버전을 얻으려면이를 수정해야합니다. –

4

그것은 예쁜 방법하지 않을 수도 있습니다,하지만 당신은 잡아 -lk Aspnet_regiis.exe를 의 출력을 구문 분석 할 수 있다면, 당신은 당신이 필요로하는 모든 정보를 얻을 수 있습니다. 하여 SharePoint VHD의 출력 예 : IIS에서

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_Regiis -lk 
W3SVC/ 1.1.4322.2407 
W3SVC/1/ROOT/Reports/ 2.0.50727.0 
W3SVC/1/ROOT/ReportServer/  2.0.50727.0 
W3SVC/1619303638/Root/ 2.0.50727.0 
W3SVC/1619303638/Root/_layouts/images/ 1.1.4322.2407 
W3SVC/1619303638/Root/_layouts/inc/  1.1.4322.2407 
W3SVC/1720207907/root/ 2.0.50727.0 
W3SVC/1720207907/root/SharedServices1/ 2.0.50727.0 
W3SVC/1848312571/Root/ 2.0.50727.0 
W3SVC/1848312571/Root/_layouts/images/ 1.1.4322.2407 
W3SVC/1848312571/Root/_layouts/inc/  1.1.4322.2407 
W3SVC/784543535/Root/ 2.0.50727.0 
W3SVC/784543535/Root/_layouts/images/ 1.1.4322.2407 
W3SVC/784543535/Root/_layouts/inc/  1.1.4322.2407 
W3SVC/98413328/Root/ 2.0.50727.0 
W3SVC/98413328/Root/_layouts/images/ 1.1.4322.2407 
W3SVC/98413328/Root/_layouts/inc/  1.1.4322.2407 
+0

정말 예쁘다! –