IIS 7 配置路径
我正在尝试使我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终将绑定提交到
MACHINE/WEBROOT/APPHOST
。您应该去查看以下位置的架构文件:
它们将帮助您确定设置的所属位置。
更新:
根据您的评论:
这一切都取决于。 IIS7 支持名为 功能的机制代表团。如果某个功能被委托,则意味着用户可以在其本地
web.config
中配置该功能。某些功能在system.webServer
下配置,其他功能在system.web
下配置。用户在其
web.config
中可以和不可以本地配置的内容由两个文件中的条目控制:%systemroot%\system32\inetsrv\config\administration.config
%systemroot%\system32\inetsrv\config\applicationHost.config
如果您去查看 IIS7 配置架构:
您会发现有两种主要类型的节:
在
system.applicationHost
下可配置的任何内容通常不被视为用户可修改的配置项。事实上,如果您打开applicationHost.config
,您将看到:注意到
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:
They will help you identify where settings should belong.
Update:
Per your comment:
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 undersystem.webServer
, otherssystem.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:
What you'll find is that there are two main types of section:
Anything that is configurable under
system.applicationHost
is generally not considered a user modifiable configuration item. In fact if you openapplicationHost.config
you will see:Notice the
allowDefinition="AppHostOnly"
? That's basically telling you that these settings can't be configured inweb.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.
听起来您正在尝试构建一个通用工具来管理配置,因此您可能需要考虑遵循 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.