如何在 IIS 7.x 上使用 DirectoryServices 正确读取 AccessFlags 属性?

发布于 2024-09-27 18:23:31 字数 1015 浏览 7 评论 0原文

我在 Windows 7 x64 上有 IIS 7.5,在 Windows 2008 SP2 x86 上有 IIS 7.0。在这两种情况下,所有 IIS 6 兼容性功能都已安装。

在 IIS 管理器中,我创建了一个名为 TestAccess 的虚拟目录,其物理路径是

c:\inetpub\wwwroot\TestAccess

我尝试使用 VB.NET 代码读取 AccessFlags 属性,如下所示:

Dim de As New DirectoryEntry("IIS://localhost/W3SVC/1/Root/TestAccess")
Console.WriteLine(de.Properties("AccessRead").Item(0))
Console.WriteLine(de.Properties("AccessWrite").Item(0))
Console.WriteLine(de.Properties("AccessExecute").Item(0))
Console.WriteLine(de.Properties("AccessSource").Item(0))
Console.WriteLine(de.Properties("AccessScript").Item(0))

不幸的是,此代码似乎从中获取(继承的)信息,

c:\Windows\System32\inetsrv\config\applicationHost.config

但如果我进入IIS 管理器,选择虚拟目录,选择处理程序映射,单击编辑功能权限并进行任何更改,实际更改将写入

c:\inetpub\wwwroot\TestAccess\web.config

如果不是 DirectoryServices,我应该使用什么检测代码来获取 applicationHost.config 和特定的组合视图目录的 web.config 文件以便我可以读取这些属性的有效值?我更喜欢同时适用于 IIS 6.0 和 7.x 的东西。

I have IIS 7.5 on Windows 7 x64 and IIS 7.0 on Windows 2008 SP2 x86. In both cases, all the IIS 6 Compatibility features have been installed.

In IIS Manager, I have created a virtual directory named TestAccess with the physical path

c:\inetpub\wwwroot\TestAccess

I am trying to read the AccessFlags properties using VB.NET code like this:

Dim de As New DirectoryEntry("IIS://localhost/W3SVC/1/Root/TestAccess")
Console.WriteLine(de.Properties("AccessRead").Item(0))
Console.WriteLine(de.Properties("AccessWrite").Item(0))
Console.WriteLine(de.Properties("AccessExecute").Item(0))
Console.WriteLine(de.Properties("AccessSource").Item(0))
Console.WriteLine(de.Properties("AccessScript").Item(0))

Unfortunately, this code appears to grab the (inherited) information from

c:\Windows\System32\inetsrv\config\applicationHost.config

but if I go into IIS Manager, select the virtual directory, select Handler Mappings, click Edit Feature Permissions and make any changes, the actual changes are written to

c:\inetpub\wwwroot\TestAccess\web.config

If not DirectoryServices, what instrumentation code should I use to get a combined view of the applicationHost.config and the specific directory's web.config files so I can read the effective values of those properties? I would prefer something that works with both IIS 6.0 and 7.x.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2024-10-04 18:23:31

如您所知,System.DirectoryServices 位包装了 IIS6.0 兼容层。但兼容层只是提供了到仅在 IIS6 中支持的功能的映射。

IIS6 对 ASP.NET 没有真正的了解,只是它是映射到一个或两个 ISAPI 过滤器的脚本(以及对 IIS MMC 的一个小更新,以允许将脚本映射从一个版本的 ASP.NET 整体切换到另一个版本) 。

IIS6 将其大部分配置存储在元数据库中,因此 API 旨在操作元数据库存储。 IIS6 元数据库不了解 ASP.NET 和 web.config,同样 ASP.NET 只是一个脚本映射。

站点的 web.config 文件中从来没有任何控制 IIS6 的设置。 IIS 6 对该文件是盲目的,因此兼容性层也是盲目的,并且不考虑可能在站点 部分中配置的其他设置web.config 文件。

IIS6 兼容层仅通过修改 applicationHost.config 中的等效设置来模拟元数据库。

IIS7 更改了 web.config 文件中的游戏和设置(在 部分下),现在在站点启动时被同化到站点的整体运行时配置中。

因此,底线是,如果您想要 IIS7 站点配置的聚合视图,则需要使用新的托管 API 的 Microsoft.Web.AdministrationMicrosoft.Web.Management > 您还可以使用appcmd.exe 命令行配置工具,

您可以使用这些工具指定要读取或修改设置的位置,例如在应用程序主机级别或本地站点级别。 MMC

应该注意的是,除非被更具体位置(例如站点或子目录)的配置文件覆盖,否则许多设置始终被假定为继承。IIS7

控制台倾向于进行更改(例如处理程序映射、mime 类型等)。 )在站点本地 web.config 文件中。如果您需要确保这些更改更加持久且不存在被删除的风险,那么您可以将它们提交到 applicationHost.config 中。 > 文件,但您需要使用 appcmd.exe(带有 /commit:apphost 开关)或使用 VB.NET、C# 或PowerShell。

As you're aware the System.DirectoryServices bits wrap the IIS6.0 compatibility layer. But the compatibility layer simply provides a mapping to features that were supported in IIS6 only.

IIS6 had no real knowledge of ASP.NET other that it being a script mapping to one or two ISAPI filters (and a minor update to the IIS MMC to permit switching en-mass the script maps from one version of ASP.NET to another).

IIS6 stores much of its configuration in the metabase so the API's are designed to manipulate the metabase store. The IIS6 metabase is ignorant of ASP.NET and web.config, again ASP.NET is just a script map.

There were never any settings to control IIS6 in a site's web.config file. IIS 6 is blind to this file and so the compatibility layer is also blind and doesn't take into account additional settings that might be configured in the <system.webServer> section of a site's web.config file.

The IIS6 compatibility layer emulates the metabase by modifying equivalent settings in applicationHost.config only.

IIS7 changes the game and settings in web.config files (under the <system.webServer> section are now assimilated into the overall runtime configuration of a site when it starts.

So the bottom line is if you want an aggregated view of an IIS7 site's configuration you'll need to use the new managed API's Microsoft.Web.Administration and Microsoft.Web.Management. You can also use the appcmd.exe command line configuration tool as well.

Using these tools you can specify where you want to read or modify settings e.g. at the Application Host level or at the local site level.

It should be noted that many settings are always assumed to be inherited unless overridden by a configuration file at a more specific location (e.g. site or subdirectory).

The IIS7 MMC console tends to place changes (such as to handler mappings, mime types etc) in the site local web.config file. If you need to ensure these changes are more persistent and not at risk of being deleted then you can commit them to the applicationHost.config file, but you need to use either appcmd.exe (with the /commit:apphost switch or work with the managed API's using tools such as VB.NET, C# or PowerShell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文