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.
Create a file called
RegistriesSchema.xml
and copy and paste the following XML:Grab a copy of a tool called
IisSchema.exe
from here:Unzip and make sure both the exe and the xml schema file are in the same folder.
From an administrator command line (i.e. open
cmd.exe
using "Run As Administrator"):This will do two things:
%systemroot%\system32\inetsrv\config\schema
adds the following XML to
applicationHost.config
: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 yourweb.config
file for each site or you could add it to the rootmachine.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):
For .NET Framework 4.0:
If you put your assembly's
configSection/sectionGroup
in yourmachine.config
file(s) then you don't need to declare it in every site'sweb.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'sweb.config
file this breaks the IIS7.5 Configuration Editor. I'm trying to get to the bottom of this: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:Also, and importantly, remove the section reference from
applicationHost.config
: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 ininetsrv\config
) and create theRegistriesSchema.xml
file directly ininetsrv\config\schema
.You can find out more about extending the IIS7 schema here:
You can poke about the existing schema files to learn more about how to construct these settings. They can be found in:
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.