IIS 7 配置路径

发布于 2024-10-14 08:24:32 字数 524 浏览 2 评论 0原文

我正在尝试使我的 C++ ahadmin 应用程序与 IIS 7 兼容。我的应用程序需要读取网站配置(通过 IIS 6 中的元数据库属性)。

我读了很多关于配置路径的文章,我想我很清楚它是如何工作的 - 但我不确定一件事:

要进行配置,我可以提交 MACHINE/WEBROOT/APPHOST/ 路径或机器/WEBROOT/APPHOST/默认网站。

据我了解,后者指的是特定网站的实际web.config,前者指的是通用的applicationHost.config文件,其中设置了常规设置。

但是,我的应用程序不知道 web.config 文件是否存在。

我的问题:如果我想到达此路径 - Object.ConfiguredObject.Site.Bindings,我是否需要提交 APPHOST 路径或 APPHOST/Default网站 路径?

我如何在运行时知道这一点?

I am trying to make my c++ ahadmin application compatible to IIS 7. My app needs to read the websites configuration (via metabase properties in IIS 6).

I read a lot of articles about the configuration paths and I think I have a good idea of how it work - however I am not sure of one thing:

To get to the configuration, I can either commit the MACHINE/WEBROOT/APPHOST/ path or the MACHINE/WEBROOT/APPHOST/Default Web Site.

I understand that the latter refers to the actual web.config of the specific website, and the former refers to the general applicationHost.config file, in which general settings are set.

My app doesn't know however whether a web.config file exists.

My question: if I want to get to this path - Object.ConfiguredObject.Site.Bindings, do I need to commit the APPHOST path or the APPHOST/Default Web Site path?

How do I know that in runtime?

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

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

发布评论

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

评论(2

寒江雪… 2024-10-21 08:24:32

您始终将绑定提交到MACHINE/WEBROOT/APPHOST

您应该去查看以下位置的架构文件:

%systemroot%\System32\inetsrv\config\schema

它们将帮助您确定设置的所属位置。

更新:

根据您的评论:

例如,AccessSSLFlags 会
被映射到
ConfigurationSection.AccessSection.SslFlags
- 在这种情况下我将提交哪一部分?我怎么知道我是哪个部分
需要提交吗?

这一切都取决于。 IIS7 支持名为 功能的机制代表团。如果某个功能被委托,则意味着用户可以在其本地 web.config 中配置该功能。某些功能在 system.webServer 下配置,其他功能在 system.web 下配置。

用户在其 web.config 中可以和不可以本地配置的内容由两个文件中的条目控制:

%systemroot%\system32\inetsrv\config\administration.config
%systemroot%\system32\inetsrv\config\applicationHost.config

如果您去查看 IIS7 配置架构:

%systemroot%\System32\inetsrv\config\schema\IIS_schema.xml

您会发现有两种主要类型的节:

system.applicationHost/xxxx
system.webServer/xxxx

system.applicationHost 下可配置的任何内容通常不被视为用户可修改的配置项。事实上,如果您打开 applicationHost.config,您将看到:

<sectionGroup name="system.applicationHost">
  <section name="applicationPools" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="configHistory" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="customMetadata" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="listenerAdapters" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="log" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="serviceAutoStartProviders" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="sites" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="webLimits" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
</sectionGroup>

注意到 allowDefinition="AppHostOnly" 了吗?这基本上是在告诉您这些设置无法在 web.config 中配置。

功能委托的工作原理范围太广,无法在答案中涵盖,因此我建议您阅读上面链接的文章。

You will always commit your bindings to MACHINE/WEBROOT/APPHOST.

You should go have a look at the schema files in:

%systemroot%\System32\inetsrv\config\schema

They will help you identify where settings should belong.

Update:

Per your comment:

So for example, AccessSSLFlags would
be mapped to
ConfigurationSection.AccessSection.SslFlags
- what section will I commit in that case? How do I know which section I
need to commit?

That all depends. IIS7 supports a mechanism called Feature Delegation. If a feature is delegated then this means a user can configure that feature in their local web.config. Some features are configured under system.webServer, others system.web.

What a user can and can't configure locally in his/her web.config is controlled by entries in two files:

%systemrooot%\system32\inetsrv\config\administration.config
%systemrooot%\system32\inetsrv\config\applicationHost.config

If you go and look at the IIS7 configuration schema in:

%systemroot%\System32\inetsrv\config\schema\IIS_schema.xml

What you'll find is that there are two main types of section:

system.applicationHost/xxxx
system.webServer/xxxx

Anything that is configurable under system.applicationHost is generally not considered a user modifiable configuration item. In fact if you open applicationHost.config you will see:

<sectionGroup name="system.applicationHost">
  <section name="applicationPools" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="configHistory" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="customMetadata" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="listenerAdapters" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="log" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="serviceAutoStartProviders" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="sites" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
  <section name="webLimits" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
</sectionGroup>

Notice the allowDefinition="AppHostOnly"? That's basically telling you that these settings can't be configured in web.config.

The scope of how feature delegation works is far too wide to cover in an answer so I suggest you read the article linked to above.

脸赞 2024-10-21 08:24:32

听起来您正在尝试构建一个通用工具来管理配置,因此您可能需要考虑遵循 IIS 管理器遵循的类似模式;简而言之,它总是尝试将配置保存到可能的最深路径。这意味着它总是会通过查看该部分是否被锁定来将其提交到可以的位置。它使用托管代码 (Microsoft.Web.Administration),但您可以使用 AppHostElement.GetMetadata("isLocked") 从 C++ 访问相同的数据。
顺便说一句,如果您使用 C++,我强烈建议直接使用 AHADMIN(而不是 WMI 或其他任何东西),特别是 IAppHostWritableAdminManager

因此,算法是将 CommitPath 设置为与指定的 GetAdminSection 配置路径相同的值。然后检查 IsLocked,如果是,则删除最后一个“路径部分”(修剪从最后一个“/”开始的部分),然后再次阅读,直到找到该部分解锁的位置。那是你可以保存它的最深处。另外,如果它是 system.web 部分,您将需要在某个时候切换到 MACHINE/WEBROOT。 IsLocked 将尊重诸如“部分定义”允许位置之类的内容以及其他必需的内容。如果你想让它防弹,你甚至需要检查属性级锁定,但我认为这是相当先进的。

It sounds like you are trying to build a generic tool to manage configuration, and so you might want to consider to follow a similar pattern that IIS Manager follows; in short, it always tries to save configuration to the deepest path possible. What this means is that it will always Commit it to the place where it can, by looking at if the section is locked or not. It uses Managed code (Microsoft.Web.Administration), but you can access the same data from C++ using AppHostElement.GetMetadata("isLocked").
By the way if you are using C++, I would STRONGLY recommend using AHADMIN directly (and not WMI, or anything else), in particular IAppHostWritableAdminManager.

So the algorithm would be, set the CommitPath to the same value as the GetAdminSection configuration path specified. Then check for IsLocked, if it is then remove the last "path part" (trim starting the last '/'), and read again till you find the place where the section is unlocked. That is the deepest place where you can save it. Also, you will need to switch to MACHINE/WEBROOT at some point if it is a system.web section. IsLocked will respect things like Section Definition allow location, and other things that are required. If you want to make it bullet proof you would even need to check for attribute-level locking, but I think that is quite advanced.

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