简体   繁体   中英

Programmatic check if the IIS6 compatibility role is enabled/disabled in IIS7

如果在IIS7上启用/禁用IIS6兼容性角色,如何使用C#进行检查?

you can check read the value in the registry

HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp\Components\WMICompatibility

or, you can ouput the content of servermanagercmd to an xml file and parse that file looking for the iis6 compatibility component

ServerManagerCmd -query [SaveFile.xml]

If your doing this on R2, servermanagercmd is now deprecated so you might want to use powershell to achieve the same check. Here are some powershell examples, in this case done remotely http://www.techmumbojumblog.com/?p=217

The WMI approach from the previous answer is probably good as well, espcialy if you have more configuration tasks to perform on the IIS, after validating that the compatibility tool is install.

btw, if you do find configuration settings that are not handled by the compatibility component, here is what I found doing it from C#, what I was configuring through wmi back in iis6 worked fine at the website level and under(website, virtual dir and pools), but to configure the webserver level, I had to use the the api that's installed with iis7, Microsoft.Web.Administration.dll from System32\\inetsrv.

using Microsoft.Web.Administration;

Please, someone give a good answer for this! As motivation, here's a very bad answer =)

// Ok, this is stupid, but I can't find any other way to do this
// Detect whether we're in integrated mode or not
#warning GIANT HACK FOR IIS7 HERE
try
{
    var x = HttpContext.Current.CurrentNotification;
    _isIntegratedMode = true;
}
catch (PlatformNotSupportedException)
{
    _isIntegratedMode = false;
}
catch (NullReferenceException)
{
    _isIntegratedMode = true;
}

This is what our code currently does to figure this out (yes, I know it's appallingly bad - hence the warnings)

You probably can do that by programmatically querying the WMI provider of IIS7. http://learn.iis.net/page.aspx/162/managing-sites-with-iis-7039s-wmi-provider/

I don't know if you can do that through powershell.

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