在 IIS 中编辑配置自定义部分 [英] Edit config custom section in IIS

查看:33
本文介绍了在 IIS 中编辑配置自定义部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理由 5 个不同的网站和一些共享程序集组成的大型 ASP.NET 项目(我们使用 ASP.NET 3.5).最近我将自定义部分添加到每个站点的 web.config 文件中.当我部署所有这些应用程序时,每个站点都单独部署在同一个应用程序池下.有什么办法可以在站点级别的 IIS 中编辑此部分,就像您可以编辑每个站点的 ConnectionString 部分一样?

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

<部分名称="注册表设置"type="Registries.Business.Utilities.RegistriesConfigurations"/></sectionGroup ><注册表自定义设置><RegistriesSettings ContextCommandTimeout="30"logLinq="true" DisplayUser="true" BaseReportPath="/DDD/"ReportingServer="http://patriot-regdev:8000/ReportServer"TopInstitution="1000001"/></RegistriesCustomSettings>

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

解决方案

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

  1. 创建一个名为 RegistriesSchema.xml 的文件,然后复制并粘贴以下 XML:

    <sectionSchema name="RegistriesCustomSettings"><元素名称="注册表设置"><属性名称=ContextCommandTimeout"类型=整数"验证类型=整数范围"验证参数=1,600"允许无限=真"defaultValue="30"/><属性名称=logLinq"类型=布尔"defaultValue="True"/><属性名称=显示用户"类型=布尔"defaultValue="True"/><属性名称="BaseReportPath"类型=字符串"validationType="nonEmptyString"/><属性名称="ReportingServer"类型=字符串"validationType="nonEmptyString"/><属性名称="TopInstitution"类型=字符串"validationType="nonEmptyString"/></元素></sectionSchema></configSchema>

  2. 从这里获取名为 IisSchema.exe 的工具的副本:

    <块引用>

    <小时>

    更新 2:

    我认为关于这方面的 MS 文档有点虚假,特别是在您的自定义配置部分需要由 ASP.NET 使用并可在 IIS 管理器配置编辑器中编辑的情况下.诀窍似乎是在 RegistriesSchema.xml 文件中如下声明架构:

    <属性名称=ContextCommandTimeout"类型=整数"验证类型=整数范围"验证参数=1,600"允许无限=真"defaultValue="30"/><属性名称=logLinq"类型=布尔"defaultValue="True"/><属性名称=显示用户"类型=布尔"defaultValue="True"/><属性名称="BaseReportPath"类型=字符串"validationType="nonEmptyString"/><属性名称="ReportingServer"类型=字符串"validationType="nonEmptyString"/><属性名称="TopInstitution"类型=字符串"validationType="nonEmptyString"/></sectionSchema></configSchema>

    另外,重要的是,从 applicationHost.config 中删除部分引用:

    这不是必需的.

    此外,您实际上并不需要使用 iisschema.exe 工具,只需获取 NotePad2 的副本(它是一个 64 位编辑器,您需要它来编辑 inetsrvconfig) 并直接在 inetsrvconfigschema 中创建 RegistriesSchema.xml 文件.

    <小时>

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

    <块引用>

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

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

    %systemroot%system32inetsrvconfigschema

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

    I am working on big ASP.NET project(we using ASP.NET 3.5) which comprised of 5 different WebSites and some shared assemblies. Recently I added custom section into web.config files for each site. When I deploy all these applications, each site is deployed separately under same app pool. Is there any way to make this section editable in IIS on site level, just like you can edit ConnectionString section for each site?

    Sections I added all look like this:

    <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>
    

    We using are IIS 7.0, 2008 RC 2.

    解决方案

    Yes there is a way to do this by extending the IIS configuration schema.

    1. Create a file called RegistriesSchema.xml and copy and paste the following 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>
      

    2. Grab a copy of a tool called IisSchema.exe from here:

      IISSCHEMA.EXE - A tool to register IIS7 configuration sections

      Unzip and make sure both the exe and the xml schema file are in the same folder.

    3. From an administrator command line (i.e. open cmd.exe using "Run As Administrator"):

      IISSCHEMA.EXE /install RegistriesSchema.xml

      This will do two things:

      • drops the schema file into %systemroot%system32inetsrvconfigschema
      • adds the following XML to applicationHost.config:

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

    4 . Launch IIS Manager and open the feature settings for your website and open the Configuration Editor:

    5 . Select the Section drop down list:

    If all is good you should see "RegistriesCustomSettings", select this item.

    6 . You can now edit these settings and they'll be added to your site's web.config file:

    This is just a demonstration so the schema settings may not be quite right and will probably need some fine tuning.

    What To Do With <sectionGroup name="RegistriesCustomSettings">?:

    You will still need to add the configSection/sectionGroup xml to your web.config file for each site or you could add it to the root machine.config file for whatever version of ASP.NET you're using, i.e.:

    For .NET Framework 2.0 (which also applies to .NET3.0 and 3.5):

    %systemroot%Microsoft.NETFrameworkv2.050727CONFIGmachine.config

    %systemroot%Microsoft.NETFramework64v2.050727CONFIGmachine.config

    For .NET Framework 4.0:

    %systemroot%Microsoft.NETFrameworkv4.0.30319CONFIGmachine.config

    %systemroot%Microsoft.NETFramework64v4.0.30319CONFIGmachine.config

    If you put your assembly's configSection/sectionGroup in your machine.config file(s) then you don't need to declare it in every site's web.config. If quite a few sites are going to be using this assembly then this may be good timesaver.

    Update:

    There seems to be a bug or limitation in the IIS7.5 Configuration Editor. It appears that if you have your own custom configSections <sectionGroup> or <section> declarations in your site's web.config file this breaks the IIS7.5 Configuration Editor. I'm trying to get to the bottom of this:

    ASP.NET custom configuration section declaration breaks IIS Manager Configuration Editor


    Update 2:

    I think the MS docs on this are a bit bogus particularly where your custom config section needs to be consumable by ASP.NET and editable in the IIS Manager Configuration Editor. The trick seems to be to declare the schema as follows in the RegistriesSchema.xml file:

    <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>
    

    Also, and importantly, remove the section reference from applicationHost.config:

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

    This is not required.

    Additionally, you don't actually need to use the iisschema.exe tool, just grab a copy of NotePad2 (it's a 64bit editor, you need this to edit anything in inetsrvconfig) and create the RegistriesSchema.xml file directly in inetsrvconfigschema.


    You can find out more about extending the IIS7 schema here:

    Extending IIS 7.0 Schema and Accessing the Custom Sections Using MWA

    You can poke about the existing schema files to learn more about how to construct these settings. They can be found in:

    %systemroot%system32inetsrvconfigschema

    Caveat: The example above was tested on IIS7.5 x64 RTM on Windows 7 x64 Ultimate. You mention that you're running a release candidate so your mileage may vary because of that.

    这篇关于在 IIS 中编辑配置自定义部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆