2010-07-23 3 views
2

웹 사이트를 등록하기 위해 설치 프로그램을 설정하려고합니다. 현재 Windows Server 2003에서 응용 프로그램 풀과 웹 사이트를 만들었습니다. 불행하게도 IP 주소를 설정하기 위해 ServerBindings 속성을 수정하려고 할 때마다 예외가 발생합니다. 나는 여기에 문서가 http://msdn.microsoft.com/en-us/library/ms525712%28VS.90%29.aspx에 나에게 말했기 때문에 이것을 처음 시도했다. 현재 VB.NET을 사용하고 있지만 C# 응답은 C#을 사용하여 전환해야하므로 괜찮습니다.IIS 6.0의 서버 바인딩을 프로그래밍 방식으로 설정하는 중

siteRootDE.Properties.Item("ServerBindings").Item(0) = "<address>" 

이것은 ArgumentOutOfRangeException을 발생시킵니다. 나는 그것을 확인하고, 나는이 같은 목록에 새 항목을 만들려고하면 서버 바인딩은 크기가 0입니다 :

siteRootDE.Properties.Item("ServerBindings").Add("<address>") 

내가 그 때 내가 COMException를 얻을 수 있습니다.

등록 된 등록 정보 키를보고 ServerBindings를 찾을 수 없습니다. 그러나 IIS를 통해 웹 사이트를 만들면 ServerBinding을 올바르게 생성하고 볼 수 있습니다.

ServerBindings를 표시하려면 어떻게해야합니까?

편집 : 코드를 C#으로 이동하고 시도했습니다. 위의 두 가지 중 하나가 주어지면 VB.NET에서 충돌이 발생하지만 C#에서는 오류가 발생합니다. 하지만 그 코드는 여전히 아무 것도하지 않는 것 같습니다. 그냥 조용히 실패합니다. 나는 이런 식으로 노력하고있어 :

// WebPage is the folder where I created the website 
DirectoryEntry siteRootDE = new DirectoryRoot("IIS://LocalHost/W3SVC/WebPage"); 
// www.mydomain.com is one of the IP addresses that shows up 
// when I used the IIS administrative program 
siteRootDE.Properties["ServerBindings"].Value = ":80:www.mydomain.com"; 
siteRootDE.CommitChanges(); 

답변

5

C#에서이 작업을 수행 할 수 있어야한다 :

webSite.Invoke("Put", "ServerBindings", ":80:www.mydomain.com"); 

또는

webSite.Properties["ServerBindings"].Value = ":80:www.mydomain.com"; 

편집 : 여기

는 샘플입니다 코드를 사용했습니다.

public static void CreateNewWebSite(string siteID, string hostname) 
{ 
    DirectoryEntry webService = new DirectoryEntry("IIS://LOCALHOST/W3SVC"); 

    DirectoryEntry website = new DirectoryEntry(); 
    website = webService.Children.Add(siteID, "IIsWebServer"); 
    website.CommitChanges(); 

    website.Invoke("Put", "ServerBindings", ":80:" + hostname); 
    // Or website.Properties["ServerBindings"].Value = ":80:" + hostname;    
    website.Properties["ServerState"].Value = 2; 
    website.Properties["ServerComment"].Value = hostname; 
    website.CommitChanges(); 

    DirectoryEntry rootDir = website.Children.Add("ROOT", "IIsWebVirtualDir"); 
    rootDir.CommitChanges(); 

    rootDir.Properties["AppIsolated"].Value = 2; 
    rootDir.Properties["Path"].Value = @"C:\Inetpub\wwwroot\MyRootDir"; 
    rootDir.Properties["AuthFlags"].Value = 5; 
    rootDir.Properties["AccessFlags"].Value = 513; 
    rootDir.CommitChanges(); 
    website.CommitChanges(); 
    webService.CommitChanges(); 
} 

또한 여기에 좋은 article을 참조하십시오.

+0

불행히도 그것은 작동하지 않았습니다. IIS에서 여전히 나타나지 않습니다. –

+0

그건 재미 있어요. 이 코드는 작업 프로그램에서 가져온 것입니다. 원한다면 전체 샘플 코드를 게시 할 수 있습니까? – Garett

+0

결국 작동이 끝났습니다. "고급"을 누르면 IIS에 표시되지만 거기에 있습니다. 내 문제는 웹 사이트 대신 rootDir에서 속성을 설정했을 수 있다고 생각합니다. –

관련 문제