Принятие Вас уже попробовало к тому, "Добавьте Ссылка...", как объяснено выше и не успешно выполняйтесь, можно взглянуть здесь . Они говорят, что необходимо встретить некоторые предпосылки:-.NET 3,5 SP1 - РЕДАКТИРОВАНИЕ Windows Installer 4.5
: Согласно этому сообщение это - известная проблема.
И это могло быть решением, которое Вы ищете:)
System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
Вот сообщение , связанное с получением идентификатора сайта.
Вот код, который может сработать для вас:
using System.DirectoryServices;
using System;
public class IISAdmin
{
public static void GetWebsiteID(string websiteName)
{
DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/w3svc");
foreach(DirectoryEntry de in w3svc.Children)
{
if(de.SchemaClassName == "IIsWebServer" && de.Properties["ServerComment"][0].ToString() == websiteName)
{
Console.Write(de.Name);
}
}
}
public static void Main()
{
GetWebsiteID("Default Web Site");
}
}
Вот ссылка на исходное сообщение .
Я не уверен, будет ли он работать на IIS7, но если вы устанавливаете компоненты совместимости с IIS6 для IIS7, он должен работать.
You are looking for ServerManager (Microsoft.Web.Administration) which provides read and write access to the IIS 7.0 configuration system.
Iterate through Microsoft.Web.Administration.SiteCollection, get a reference to your website using the Site Object and read the value of the Name property.
// Snippet
using (ServerManager serverManager = new ServerManager()) {
var sites = serverManager.Sites;
foreach (Site site in sites) {
Console.WriteLine(site.Name); // This will return the WebSite name
}
You can also use LINQ to query the ServerManager.Sites collection (see example below)
// Start all stopped WebSites using the power of Linq :)
var sites = (from site in serverManager.Sites
where site.State == ObjectState.Stopped
orderby site.Name
select site);
foreach (Site site in sites) {
site.Start();
}
Note : Microsoft.Web.Administration works only with IIS7.
For IIS6 you can use both ADSI and WMI to do this, but I suggest you to go for WMI which is faster than ADSI. If using WMI, have a look at WMI Code Creator 1.0 (Free / Developed by Microsoft). It will generate the code for you.
HTH