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

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

问题描述

我工作的大ASP.NET项目(我们使用ASP.NET 3.5),它由5个不同的网站和一些共享的组件。最近我添加自定义栏目到的web.config 文件为每个站点。当我部署所有这些应用中,每个站点是根据相同的应用程序池单独部署。
有没有什么办法,使在IIS中本节可编辑的现场水平,就像你可以编辑的ConnectionString 部分为每个站点?

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>

我们正在使用IIS 7.0,2008年2 RC

We using are IIS 7.0, 2008 RC 2.

推荐答案

是的,有办法通过扩展IIS配置模式来做到这一点。

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


  1. 创建一个名为 RegistriesSchema.xml 复制并粘贴以下XML:

  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>


  • 抓住一个名为工具的副本 IisSchema.exe 从这里开始:

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

    解压缩,并确保两个exe文件和XML schema文件都在同一个文件夹中。

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

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

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

    IISSCHEMA.EXE /install RegistriesSchema.xml

    这将做两件事情:


    • 滴模式文件%SYSTEMROOT%\\ SYSTEM32 \\ INETSRV \\设置\\架构

    • 增加了以下的XML 的applicationHost.config

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


  • 4。启动IIS管理器,然后打开该功能设置为您的网站并打开配置编辑器:

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

    5。选择部分下拉列表:

    5 . Select the Section drop down list:

    如果一切都很好,你应该看到RegistriesCustomSettings,选择此项。

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

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

    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.

    做什么用&LT; sectionGroup NAME =RegistriesCustomSettings&GT;

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

    您仍然需要在 configSection / sectionGroup XML添加到您的的web.config 文件为每个站点的,你可以把它添加到根的machine.config 文件你使用任何ASP.NET版本,即:

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

    有关的.NET Framework 2.0(也适用于.NET3.0和3.5):

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

    %systemroot%\Microsoft.NET\Framework\v2.050727\CONFIG\machine.config

    %systemroot%\Microsoft.NET\Framework64\v2.050727\CONFIG\machine.config

    有关的.NET Framework 4.0:

    For .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 文件(S),那么你不吨需要声明它在每个站点的的web.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.

    更新:

    有似乎是在IIS7.5配置编辑器中的错误或限制。看来,如果你有自己的自定义 configSections &LT; sectionGroup&GT; &lt;节&GT ; 在您的网站声明的web.config 这个文件打破了IIS7.5配置编辑器。我试图去的这条底线:

    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:

    <一个href=\"http://serverfault.com/questions/267556/asp-net-custom-configuration-section-declaration-breaks-iis-manager-configuration\">ASP.NET自定义配置节声明打破了IIS管理器配置编辑器

    更新2:

    我觉得这个MS文档是有点假特别是在您的自定义配置部分必须由ASP.NET耗材和可编辑在IIS管理器配置编辑器。诀窍似乎是作为 RegistriesSchema.xml 文件如下声明模式:

    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>
    

    此外,重要的是,删除该部分参考的applicationHost.config

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

    这不是必需的。

    此外,你实际上并不需要使用 iisschema.exe 工具,只要抓住的Notepad2的副本(这是一个64位编辑器,你需要用它来编辑任何在 INETSRV \\ CONFIG ),并创建 RegistriesSchema.xml 文件直接INETSRV \\设置\\模式

    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 inetsrv\config) and create the RegistriesSchema.xml file directly in inetsrv\config\schema.

    您可以了解更多关于此扩展架构IIS7:

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

    <一个href=\"http://learn.iis.net/page.aspx/242/extending-iis7-schema-and-accessing-the-custom-sections-using-mwa/\"相对=nofollow>扩展IIS 7.0架构和访问使用MWA的自定义栏目

    您可以戳一下现有的架构文件,以了解更多关于如何构建这些设置。它们中可以找到:

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

    %systemroot%\system32\inetsrv\config\schema

    警告:在以上IIS7.5的x64 RTM进行了测试在Windows 7旗舰版64位的例子。你提到你正在运行一个候选版本让你的里程可能会因为这个而改变。

    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天全站免登陆