如何检测ASP。NET在IIS 7中启用

时间:2022-06-01 13:03:59

The challenge is to determine whether ASP.NET is enabled within IIS7 in a reliable and correct way.

挑战在于确定ASP是否。NET在IIS7中以可靠和正确的方式启用。

Enabling/Disabling is done in this case by going into:

在这种情况下,启用/禁用是通过进入:

Server Manager -> 
    Roles -> 
        Web Server (IIS) -> 
            Remove Role Services -> 
                Remove ASP.NET

The natural place to determine this should be within the applicationHost.config file. However, with ASP.NET enabled or disabled, we still have the "ManagedEngine" module available, and we still have the isapi filter record in the tag.

确定这一点的自然位置应该在applicationHost中。配置文件。然而,随着ASP。NET启用或禁用,我们仍然有“ManagedEngine”模块可用,并且在标记中仍然有isapi过滤器记录。

The best I can find at the moment is to check if the <isapiCgiRestriction> tag includes the aspnet_isapi.dll, or that the ASPNET trace provider is available.

目前我能找到的最好的方法是检查< isapicgilimit>标记是否包含aspnet_isapi。dll,或ASPNET跟踪提供程序可用。

However these aren't detecting the presence of the ASP.NET config directly, just a side effect that could conceivably be reconfigured by the user.

但是这些并没有检测到ASP的存在。NET配置直接,只是一个可以被用户重新配置的副作用。

I'd rather do this by examining the IIS configuration/setup rather than the OS itself, if possible, although enumerating the Roles & Services on the server might be acceptable if we can guarantee that this technique will always work whenever IIS7 is used.

如果可能的话,我宁愿检查IIS配置/设置,而不是操作系统本身,尽管如果我们能够保证IIS7在使用时始终有效,那么枚举服务器上的角色和服务可能是可以接受的。

Update

更新

Thanks for the responses. Clarifying exactly what I want to do, I'm pulling settings from a variety of places in the server's configuration into a single (readonly) view to show what the user needs to have configured to allow the software to work.

谢谢你的回复。明确我想要做什么,我将从服务器配置中的不同位置将设置拉到单个(只读)视图中,以显示用户需要配置什么以允许软件工作。

One of the settings I need to bring in is this one: 如何检测ASP。NET在IIS 7中启用

我需要引入的一个设置是:

The one highlighted in red.

那个用红色突出显示。

I don't need to manipulate the setting, just reproduce it. I want to see whether the user checked the ASP.NET box when they added the IIS role to the server, as in this example they clearly didn't.

我不需要操作这个设置,只需要复制它。我想看看用户是否检查了ASP。当他们将IIS角色添加到服务器时,就像在这个例子中他们显然没有那样做。

I'd like to do this by looking at something reliable in IIS rather than enumerating the role services because I don't want to add any platform specific dependencies on the check that I don't need. I don't know if it will ever be possible to install IIS7 on a server that doesn't have the Roles/Services infrastructure, but in preference, I'd rather not worry about it. I also have a load of libraries for scrubbing around IIS already.

我想通过在IIS中查找一些可靠的东西来实现这一点,而不是列举角色服务,因为我不想在不需要的检查中添加任何特定于平台的依赖项。我不知道是否有可能在没有角色/服务基础设施的服务器上安装IIS7,但我宁愿不为此担心。我也有大量的库,用来在IIS上进行刷洗。

However, I'm also having trouble finding out how to enumerate the Roles/Services at all, so if there's a solution that involves doing that, it would certainly be useful, and much better than checking the side effect of having the ASPNET trace provider lying around.

但是,我也很难找到如何枚举角色/服务的方法,所以如果有一个解决方案需要这样做,那么它肯定是有用的,而且比检查ASPNET跟踪提供程序的副作用要好得多。

Unfortunately, if you don't check the ASP.NET button, you can still get the ManagedEngine module in the IIS applicationHost.config file, so it's not a reliable check. You can also have ASP.NET mapped as an isapi filter, so checking them isn't enough. These things are especially problematic in the case where ASP.NET was installed but has been removed.

不幸的是,如果您不检查ASP。NET按钮,您仍然可以在IIS applicationHost中获得ManagedEngine模块。配置文件,所以这不是一个可靠的检查。你也可以有ASP。NET映射为isapi过滤器,因此仅检查它们是不够的。在ASP的情况下,这些事情特别有问题。已经安装了网络,但已被删除。

It looks like the best solution would be to examine the Role Services. However, API information on this is looking pretty rare, hence the cry for help.

看起来最好的解决方案应该是检查角色服务。然而,有关这方面的API信息非常罕见,因此需要帮助。

3 个解决方案

#1


16  

The absolute way to know if they checked that or not is to search the following registry key:

要知道他们是否检查过,绝对的方法是搜索以下注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components

In there you should see two values set to 1, ASPNET and NetFxEnvironment and NetFxExtensibility. This registry key is the IIS Setup key that contains all the components that have been enabled in IIS.

在那里,您应该看到两个值被设置为1,即ASPNET和NetFxEnvironment和NetFxExtensibility。这个注册表键是IIS设置键,它包含IIS中启用的所有组件。

#2


2  

Determining if asp.net is even an installed feature (prerequisite for enabling it) can be done through PowerShell, which implies there is .net api out there for it if you dig hard enough. The PowerShell methods:

确定asp.net是否为已安装的特性(启用它的先决条件)可以通过PowerShell来完成,这意味着如果您足够深入地挖掘的话,就会得到。net api。PowerShell的方法:

Import-Module servermanager
Get-WindowsFeature web-asp-net

Which will return an object of type Microsoft.Windows.ServerManager.Commands.Feature. The installed property is boolean and indicates whether or not the feature is installed.

它将返回一个类型为Microsoft.Windows.ServerManager.Commands.Feature的对象。已安装的属性是布尔值,并指示该特性是否已安装。

#3


0  

So do you want the easy way? Make a nice pretty .aspx page that displays as HTML with an error block in a div in a placeholder saying "You need to install ASP.NET" and have it change on ASP.NET being installed to instead say "ASP.NET is installed" and then just have the tool launch this webpage in the default browser after copying it to the directory identified in IIS as the *:80 site (or create the directory mapping in IIS programmatically by altering the XML and then removing it later)

你想要简单的方法吗?做一个漂亮的。aspx页面,它以HTML的形式显示,在一个div中有一个错误块,在占位符中写着“您需要安装ASP”。在ASP上更改。NET被安装成“ASP”。然后让工具在默认浏览器中启动这个页面,然后将它复制到IIS中指定为*:80站点的目录中(或者通过修改XML以编程方式在IIS中创建目录映射,然后将其删除)

May not be the most elegant but it does ensure that testing shows what features are truly installed versus what's in an XML file.

也许不是最优雅的,但是它确实确保了测试显示了真正安装的特性和XML文件中的特性。


Because that will scream "do it the lazy ignorant way" I'll remind you that the only way for me to know in javascript what features I can use is to test them before I try to use them, or assume they're there and watch it blow up. My point is, it doesn't matter what gets reported in a file, it matters what you can actually use. Just because C:\Windows\Micrsoft.Net\Framework\v3.xxxxxxxx exists and has files doesn't mean the dll's are registered in the GAC, does it?

因为那会让我尖叫“用懒惰的无知的方式去做”,我将提醒你,在javascript中,我知道我可以使用什么特性的唯一方法是在我尝试使用它们之前对它们进行测试,或者假设它们在那里,然后看着它爆炸。我的观点是,在文件中报告什么并不重要,重要的是你可以实际使用什么。仅仅因为C:\Windows\ Micrsoft.Net \ Framework \ v3。xxxxxxxx存在并且有文件并不意味着dll在GAC中注册,是吗?

#1


16  

The absolute way to know if they checked that or not is to search the following registry key:

要知道他们是否检查过,绝对的方法是搜索以下注册表项:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Components

In there you should see two values set to 1, ASPNET and NetFxEnvironment and NetFxExtensibility. This registry key is the IIS Setup key that contains all the components that have been enabled in IIS.

在那里,您应该看到两个值被设置为1,即ASPNET和NetFxEnvironment和NetFxExtensibility。这个注册表键是IIS设置键,它包含IIS中启用的所有组件。

#2


2  

Determining if asp.net is even an installed feature (prerequisite for enabling it) can be done through PowerShell, which implies there is .net api out there for it if you dig hard enough. The PowerShell methods:

确定asp.net是否为已安装的特性(启用它的先决条件)可以通过PowerShell来完成,这意味着如果您足够深入地挖掘的话,就会得到。net api。PowerShell的方法:

Import-Module servermanager
Get-WindowsFeature web-asp-net

Which will return an object of type Microsoft.Windows.ServerManager.Commands.Feature. The installed property is boolean and indicates whether or not the feature is installed.

它将返回一个类型为Microsoft.Windows.ServerManager.Commands.Feature的对象。已安装的属性是布尔值,并指示该特性是否已安装。

#3


0  

So do you want the easy way? Make a nice pretty .aspx page that displays as HTML with an error block in a div in a placeholder saying "You need to install ASP.NET" and have it change on ASP.NET being installed to instead say "ASP.NET is installed" and then just have the tool launch this webpage in the default browser after copying it to the directory identified in IIS as the *:80 site (or create the directory mapping in IIS programmatically by altering the XML and then removing it later)

你想要简单的方法吗?做一个漂亮的。aspx页面,它以HTML的形式显示,在一个div中有一个错误块,在占位符中写着“您需要安装ASP”。在ASP上更改。NET被安装成“ASP”。然后让工具在默认浏览器中启动这个页面,然后将它复制到IIS中指定为*:80站点的目录中(或者通过修改XML以编程方式在IIS中创建目录映射,然后将其删除)

May not be the most elegant but it does ensure that testing shows what features are truly installed versus what's in an XML file.

也许不是最优雅的,但是它确实确保了测试显示了真正安装的特性和XML文件中的特性。


Because that will scream "do it the lazy ignorant way" I'll remind you that the only way for me to know in javascript what features I can use is to test them before I try to use them, or assume they're there and watch it blow up. My point is, it doesn't matter what gets reported in a file, it matters what you can actually use. Just because C:\Windows\Micrsoft.Net\Framework\v3.xxxxxxxx exists and has files doesn't mean the dll's are registered in the GAC, does it?

因为那会让我尖叫“用懒惰的无知的方式去做”,我将提醒你,在javascript中,我知道我可以使用什么特性的唯一方法是在我尝试使用它们之前对它们进行测试,或者假设它们在那里,然后看着它爆炸。我的观点是,在文件中报告什么并不重要,重要的是你可以实际使用什么。仅仅因为C:\Windows\ Micrsoft.Net \ Framework \ v3。xxxxxxxx存在并且有文件并不意味着dll在GAC中注册,是吗?