是的,有一种方法可以通过扩展 IIS 配置架构来做到这一点。
-
创建一个名为 RegistriesSchema.xml 的文件并复制并粘贴以下 XML:
<configSchema>
<sectionSchema name="RegistriesCustomSettings">
<element name="RegistriesSettings">
<attribute name="ContextCommandTimeout"
type="int"
validationType="integerRange"
validationParameter="1,600"
allowInfinite="true"
defaultValue="30" />
<attribute name="logLinq"
type="bool"
defaultValue="True" />
<attribute name="DisplayUser"
type="bool"
defaultValue="True" />
<attribute name="BaseReportPath"
type="string"
validationType="nonEmptyString" />
<attribute name="ReportingServer"
type="string"
validationType="nonEmptyString" />
<attribute name="TopInstitution"
type="string"
validationType="nonEmptyString" />
</element>
</sectionSchema>
</configSchema>
-
从这里获取一个名为 IisSchema.exe 的工具的副本:
IISSCHEMA.EXE - A tool to register IIS7 configuration sections
解压并确保 exe 和 xml 架构文件在同一个文件夹中。
-
从管理员命令行(即使用“以管理员身份运行”打开cmd.exe):
IISSCHEMA.EXE /install RegistriesSchema.xml
这将做两件事:
4 .启动 IIS 管理器并打开您网站的功能设置并打开配置编辑器:
5 .选择部分下拉列表:
如果一切正常,您应该会看到“RegistriesCustomSettings”,请选择此项。
6 .您现在可以编辑这些设置,它们将被添加到您网站的 web.config 文件中:
这只是一个演示,因此架构设置可能不太正确,可能需要进行一些微调。
如何处理<sectionGroup name="RegistriesCustomSettings">?:
您仍然需要为每个站点将configSection/sectionGroup xml 添加到您的web.config 文件中或者您可以将它添加到根machine.config 文件中,适用于您使用的任何版本的 ASP.NET '正在使用,即:
对于 .NET Framework 2.0(也适用于 .NET3.0 和 3.5):
%systemroot%\Microsoft.NET\Framework\v2.050727\CONFIG\machine.config
%systemroot%\Microsoft.NET\Framework64\v2.050727\CONFIG\machine.config
对于 .NET Framework 4.0:
%systemroot%\Microsoft.NET\Framework\v4.0.30319\CONFIG\machine.config
%systemroot%\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config
如果您将程序集的configSection/sectionGroup 放入您的machine.config 文件中,那么您不需要在每个站点的web.config 中声明它。如果很多网站都将使用此程序集,那么这可能会节省很多时间。
更新:
IIS7.5 配置编辑器中似乎存在错误或限制。看来,如果您在站点的 web.config 文件中有自己的自定义 configSections <sectionGroup> 或 <section> 声明,这会破坏 IIS7.5 配置编辑器。我正在努力解决这个问题:
ASP.NET custom configuration section declaration breaks IIS Manager Configuration Editor
更新 2:
我认为这方面的 MS 文档有点虚假,特别是在您的自定义配置部分需要由 ASP.NET 使用并且可以在 IIS 管理器配置编辑器中编辑的情况下。诀窍似乎是在RegistriesSchema.xml 文件中声明架构如下:
<configSchema>
<sectionSchema name="RegistriesCustomSettings/RegistriesSettings">
<attribute name="ContextCommandTimeout"
type="int"
validationType="integerRange"
validationParameter="1,600"
allowInfinite="true"
defaultValue="30" />
<attribute name="logLinq"
type="bool"
defaultValue="True" />
<attribute name="DisplayUser"
type="bool"
defaultValue="True" />
<attribute name="BaseReportPath"
type="string"
validationType="nonEmptyString" />
<attribute name="ReportingServer"
type="string"
validationType="nonEmptyString" />
<attribute name="TopInstitution"
type="string"
validationType="nonEmptyString" />
</sectionSchema>
</configSchema>
另外,重要的是,从 applicationHost.config 中删除部分引用:
<section name="RegistriesCustomSettings"
overrideModeDefault="Allow"
allowDefinition="Everywhere" />
这不是必需的。
此外,您实际上不需要使用iisschema.exe 工具,只需获取NotePad2 的副本(它是一个64 位编辑器,您需要它来编辑inetsrv\config 中的任何内容)并直接创建RegistriesSchema.xml 文件在inetsrv\config\schema。
您可以在此处找到有关扩展 IIS7 架构的更多信息:
Extending IIS 7.0 Schema and Accessing the Custom Sections Using MWA
您可以查看现有架构文件以了解有关如何构建这些设置的更多信息。它们可以在以下位置找到:
%systemroot%\system32\inetsrv\config\schema
警告:上面的示例在 Windows 7 x64 Ultimate 上的 IIS7.5 x64 RTM 上进行了测试。您提到您正在运行一个候选版本,因此您的里程可能会因此而有所不同。