简体   繁体   English

编程检查IIS7中是否启用了IIS6兼容性角色

[英]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的内容输出到xml文件并解析该文件以查找iis6兼容性组件

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. 如果您在R2上执行此操作,现在不推荐使用servermanagercmd,因此您可能希望使用powershell来实现相同的检查。 Here are some powershell examples, in this case done remotely http://www.techmumbojumblog.com/?p=217 以下是一些PowerShell示例,在这种情况下远程完成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. 在验证兼容性工具是否安装之后,如果您在IIS上执行了更多配置任务,那么前一个答案中的WMI方法也可能是好的。

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. 顺便说一句,如果你确实找到了兼容组件未处理的配置设置,这就是我从C#中发现的,我在iis6中通过wmi配置的工作在网站级别和网站级别(网站,虚拟目录和池,但为了配置网络服务器级别,我不得不使用与System32 \\ inetsrv中的iis7,Microsoft.Web.Administration.dll一起安装的api。

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. 您可以通过以编程方式查询IIS7的WMI提供程序来实现。 http://learn.iis.net/page.aspx/162/managing-sites-with-iis-7039s-wmi-provider/ 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. 我不知道你是否可以通过powershell做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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