简体   繁体   中英

Is there a managed API to manage IIS 8?

In IIS7, you used to be able to use the Microsoft.Web.Administration dll to manage IIS.

I have added this reference to my project, however running the following code results in a NotImplementedException at site.Stop() :

using (var server = new ServerManager())
{
    var site = server.Sites.FirstOrDefault(s => s.Name == instanceName);
    if (site != null)
    {
        site.Stop();
    }
}

Is there an updated version of this API or an alternate method to manage IIS from .Net?

I would prefer not to use WMI or have to spawn an instance of appcmd if at all possible.

I just tested the following snippet on both IIS 8 and 7 (using 7.9.0.0 from GAC of Windows 8 & 7.0.0.0 from nuget for a 2008 R2 machine respectively)

and I have no problem stopping the site:

var manager = new ServerManager();
manager.Sites[0].Stop();
manager.Dispose();

The only thing I had to do special was run Linqpad as Administrator explicitly to get this to work. Perhaps that's your issue? Windows 8 / Server 2012 do not give you Administrator access automatically unless your application manifest mandates it. I believe this holds for 7 / 2008 R2 as well but irrelevant since you've explicitly tagged for IIS8 (UAC ftw!)

Ensure you have "impersonate" turned on and you are assigning the User and Password of the impersonate statement in the web.config with a correct administrators information. This will alleviate any further issue.

In the web.config add this statement if it is not their already.

<identity impersonate="true" userName="LOCALMACHINE\ADMINUSER" password="PASSWORD" />

Also ensure in the IISManager that you have turned impersonation ON "enabled" and Anonymous authentication OFF "disabled".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM