在IIS中编辑配置自定义部分

Vic*_*tor 8 asp.net iis-7 asp.net-3.5

我正在开发大型ASP.NET项目(我们使用ASP.NET 3.5),它包含5个不同的WebSite和一些共享程序集.最近我web.config在每个站点的文件中添加了自定义部分.部署所有这些应用程序时,每个站点都在相同的应用程序池下单独部署.是否有任何方法可以在站点级别的IIS中编辑此部分,就像您可以编辑ConnectionString每个站点的部分一样?

我添加的部分看起来像这样:

<sectionGroup name="RegistriesCustomSettings">
  <section name="RegistriesSettings" 
           type="Registries.Business.Utilities.RegistriesConfigurations"/>
</sectionGroup >

<RegistriesCustomSettings>
    <RegistriesSettings ContextCommandTimeout="30" 
           logLinq="true" DisplayUser="true" BaseReportPath="/DDD/" 
           ReportingServer="http://patriot-regdev:8000/ReportServer"
           TopInstitution="1000001" />
</RegistriesCustomSettings>
Run Code Online (Sandbox Code Playgroud)

我们使用的是IIS 7.0,2008 RC 2.

Kev*_*Kev 21

是的,有一种方法可以通过扩展IIS配置架构来实现.

  1. 创建一个名为的文件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>
    
    Run Code Online (Sandbox Code Playgroud)
  2. IisSchema.exe从这里获取一个工具的副本:

    IISSCHEMA.EXE - 注册IIS7配置节的工具

    解压缩并确保exe和xml架构文件都在同一文件夹中.

  3. 从管理员命令行(即cmd.exe使用" 以管理员身份运行" 打开):

    IISSCHEMA.EXE /install RegistriesSchema.xml

    这将做两件事:

    • 将架构文件放入 %systemroot%\system32\inetsrv\config\schema
    • 将以下XML添加到applicationHost.config:

      <section name="RegistriesCustomSettings" 
                   overrideModeDefault="Allow" 
                   allowDefinition="Everywhere" />

4.启动IIS管理器并打开网站的功能设置并打开配置编辑器:

在此输入图像描述

5.选择Section下拉列表:

在此输入图像描述

如果一切顺利,您应该看到"RegistriesCustomSettings",选择此项.

6.您现在可以编辑这些设置,它们将被添加到您网站的web.config文件中:

在此输入图像描述

这只是一个演示,因此架构设置可能不太正确,可能需要一些微调.

怎么办<sectionGroup name="RegistriesCustomSettings">?:

您仍然需要将configSection/sectionGroupxml 添加到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配置编辑器中似乎存在错误或限制.看来,如果您在站点的文件中有自己的自定义configSections <sectionGroup><section>声明,则会web.config破坏IIS7.5配置编辑器.我试图深究这个:

ASP.NET自定义配置部分声明会破坏IIS管理器配置编辑器


更新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>
Run Code Online (Sandbox Code Playgroud)

此外,重要的是,从以下部分删除部分参考applicationHost.config:

<section name="RegistriesCustomSettings" 
         overrideModeDefault="Allow" 
         allowDefinition="Everywhere" />
Run Code Online (Sandbox Code Playgroud)

这不是必需的.

此外,您实际上并不需要使用该iisschema.exe工具,只需获取NotePad2的副本(它是64位编辑器,您需要它来编辑任何内容inetsrv\config)并RegistriesSchema.xml直接创建该文件inetsrv\config\schema.


您可以在此处找到有关扩展IIS7架构的更多信息:

使用MWA扩展IIS 7.0架构和访问自定义节

您可以查看现有的架构文件,以了解有关如何构建这些设置的更多信息.它们可以在以下位置找到:

%systemroot%\system32\inetsrv\config\schema

警告:上面的示例在Windows 7 x64 Ultimate上的IIS7.5 x64 RTM上进行了测试.你提到你正在运行一个候选版本,所以你的里程可能会因此而有所不同.