Edit Custom Configuration Section in IIS

I am working on a large ASP.NET project (we use ASP.NET 3.5), which consists of 5 different WebSites and some common assemblies. I recently added a custom section to the web.config files for each site. When I deploy all of these applications, each site is deployed separately in the same application pool. Is there a way to make this section editable in site-level IIS, just as you can edit the ConnectionString section for each site?

The sections I added are as follows:

 <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 are using IIS 7.0, 2008 RC 2.

+8
source share
1 answer

Yes, there is a way to do this by expanding the IIS configuration scheme.

  • 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> 
  • Take a copy of the tool called IisSchema.exe from here:

    IISSCHEMA.EXE - a tool for registering IIS7 configuration sections

    Unzip and make sure that both exe and xml files are in the same folder.

  • In the admin command line (i.e., open cmd.exe using "Run as administrator"):

      IISSCHEMA.EXE / install RegistriesSchema.xml 

    This will do two things:

    • displays the schema file in %systemroot%\system32\inetsrv\config\schema
    • Adds the following XML to applicationHost.config :

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

4. Launch IIS Manager and open the function settings for your website and open the configuration editor:

enter image description here

5. Select the drop-down list in the section:

enter image description here

If all is well, you should see "RegistersCustomSettings", select this item.

6. Now you can edit these settings, and they will be added to your web.config file:

enter image description here

This is just a demo, so the schema settings may not be entirely correct and it will probably require some fine tuning.

What to do with <sectionGroup name="RegistriesCustomSettings"> ?:

You still need to add configSection/sectionGroup xml to your web.config for each site, or you can add it to the machine.config root file for any version of ASP.NET you use, that is:

For the .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 

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 

If you put your configSection/sectionGroup in your machine.config files, then you do not need to declare it on every web.config site. If quite a few sites will use this assembly, then this may be a good wait time.

Update:

There seems to be an error or limitation in the IIS7.5 configuration editor. It appears that if you have your own configSections <sectionGroup> or <section> declarations on your web.config site, this will break the IIS7.5 configuration editor. I'm trying to figure this out:

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


Update 2:

I think that the MS documents on this are a bit fictitious, especially if your custom configuration section should be consumed by ASP.NET and edited in the IIS Manager configuration editor. It seems like the trick is to declare the schema in the RegistriesSchema.xml file as follows:

 <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 link from applicationHost.config :

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

This is not required.

In addition, you really do not need to use the IisSchema.exe tool, just take a copy of NotePad2 (this is a 64-bit editor, you need this to change something in inetsrv\config ) and create the RegistriesSchema.xml file directly in inetsrv\config\schema .


You can learn more about extending the IIS7 schema here:

Extend IIS 7.0 Schema and Access User Partitions Using MWA

You can refer to existing schema files to learn more about how to create these parameters. They can be found in:

  % systemroot% \ system32 \ inetsrv \ config \ schema 

Warning. The example above was tested on IIS7.5 x64 RTM in Windows 7 x64 Ultimate. You note that you have a candidate for graduation, so your mileage may change due to this.

+20
source share

All Articles