2011-02-25 74 views
5

我已經編寫了一個程序,它接受主機名和網站名稱列表,並將它們作爲綁定添加到網站(如果它們不存在於任何網站上) 。該程序是用.NET 4.0 C#編寫的。IIS 7.0 vs 7.5網站Microsoft.Web.Administration.Site BindingCollection

本地(IIS 7.5,Win 7),下面的代碼工作正常。它檢測綁定和退出。在我的服務器上(IIS 7.0,Win Server 2008),檢查失敗並且始終添加綁定。是什麼賦予了?

這是LINQ查詢錯誤還是它是Microsoft.Web.Administration庫有一些基本的不足處理IIS 7.0?

下面是應在兩臺機器上工作的部分代碼:

ServerManager oIisMgr = new ServerManager(); 
Site oSite = oIisMgr.Sites[siteName]; 
string sBindInfo = ":80:" + this.StripUrl(hostName); 

//See if this binding is already on some site 
if (oIisMgr.Sites 
    .Where(ST => ST.Bindings.Where(B => B.BindingInformation == sBindInfo).Any()) 
    .Any()) return true; 

Binding oBinding = oSite.Bindings.CreateElement(); 
oBinding.Protocol = "http"; 
oBinding.BindingInformation = sBindInfo; 
oSite.Bindings.Add(oBinding); 

oIisMgr.CommitChanges(); 

回答

7

爲了記錄在案,我發現了什麼我的錯誤了。默認情況下,通過IIS管理控制檯,離開添加站點綁定的IP地址:'設置爲全部未分配給出此綁定的字符串:

「*:80:some.domain.com」

「:80:some.domain.com」在我的代碼使用這個//注意失蹤通配符

的綁定工作,但通過經理任何已經安裝並沒有記錄相同通過我的LINQ查詢,因爲我查詢的是主機名綁定信息的無通配符版本。