I have a simple .NET custom configuration component that allows me to specify a custom configuration group and section in my ASP.NET 2.0 web application's
web.config file:
In my web.config I have the following declarations:
This works great and my web application can read the "MySetting" value from my
web.config file.
Because these settings will be used in many web applications on Windows 2008 R2+IIS7.5 I then created an IIS Configuration Schema extension to allow this setting to be edited in IIS Manager's Configuration Editor feature rather than having to hand edit the
web.config file.
I added an IIS configuration schema extension file to %systemroot%\system32\inetsrv\config\schema containing:
The problem I am having is that when I open IIS Manager's Configuration Editor and select
SimpleConfigGroup from the section drop down list it reports the following error:
However, if I remove the <sectionGroup> declaration from the site's
web.config file I can edit the custom setting just fine using IIS Manager's Configuration Editor. However my web application can't run because the
<sectionGroup> config info is required for the custom config section.
I've tried adding the <sectionGroup> to the root machine.config (and even dropping the configuration assembly into the .NET 2.0 framework assemblies folder) but I get the same error. I also tried signing the configuration assembly thinking there
may be a trust issue but that hasn't helped either.
What I find strange is that the usual .NET Framework <configSections> in
machine.config don't upset the IIS Manager Configuration Manager, e.g. for system.web yet my custom config sections do.
Why is this? Is it a bug in the Configuration Editor?
If anyone cares to try this here's the source to the SimpleConfigGroup and
SimpleConfigSection classes:
SimpleConfigGroup.cs:
using System.Configuration;
namespace CustomSettingsLib
{
public class SimpleConfigGroup : ConfigurationSectionGroup
{
[ConfigurationProperty("SimpleConfigSection")]
public SimpleConfigSection SimpleConfigSection
{
get { return (SimpleConfigSection)this.Sections["SimpleConfigSection"]; }
}
}
}
SimpleConfigSection.cs:
using System.Configuration;
namespace CustomSettingsLib
{
public class SimpleConfigSection : ConfigurationSection
{
[ConfigurationProperty("MySetting", IsRequired = false)]
public string MySetting
{
get { return (string)this["MySetting"]; }
}
}
}
Thank you for providing detailed information. According to your description, the configuration seems to be correct. Have you tried iisreset to see if this address the issue?
Also please try to modify the setting as following to see if this work for you:
Thanks for the response. I actually arrived at the schema change you describe under my own steam after spelunking the ASPNET_schema.xml file and wondering why .NET's own <configSection> settings in machine.config didn't cause IIS Manager's Configuration
Editor to choke. Then I noticed the use of <sectionSchema name="system.web/...">.
Also seems that you don't need to declare anything extra in applicationHost.config to allow the config editor to pick up this style of schema extension.
If you're bored you can read this question I also posted on Server Fault with my eventual progress to getting this working.
But hadn't realised that whilst these were describing extensions to the existing system.webServer schema definitions, it's also the style you need to use if you have your own schema extension that needs to be consumable by ASP.NET *and* the configuration
editor GUI.
kevin_k
8 Posts
ASP.NET custom config section breaks IIS Manager Configuration Editor
May 06, 2011 03:26 PM|LINK
I have a simple .NET custom configuration component that allows me to specify a custom configuration group and section in my ASP.NET 2.0 web application's web.config file:
In my web.config I have the following declarations:
<configuration>
<configSections>
<sectionGroup
name="SimpleConfigGroup"
type="CustomSettingsLib.SimpleConfigGroup, CustomSettingsLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7a58d3af5d6768c9">
<section
name="SimpleConfigSection"
type="CustomSettingsLib.SimpleConfigSection, CustomSettingsLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7a58d3af5d6768c9"/>
</sectionGroup>
</configSections>
<SimpleConfigGroup>
<SimpleConfigSection MySetting="Hello World" />
</SimpleConfigGroup>
</configuration>
This works great and my web application can read the "MySetting" value from my web.config file.
Because these settings will be used in many web applications on Windows 2008 R2+IIS7.5 I then created an IIS Configuration Schema extension to allow this setting to be edited in IIS Manager's Configuration Editor feature rather than having to hand edit the web.config file.
I added an IIS configuration schema extension file to %systemroot%\system32\inetsrv\config\schema containing:
<configSchema>
<sectionSchema name="SimpleConfigGroup">
<element name="SimpleConfigSection">
<attribute name="MySetting"
type="string"
validationType="nonEmptyString" />
</element>
</sectionSchema>
</configSchema>
I then added the following section definition to IIS's applicationHost.config file in the <configSections> element:
<section name="SimpleConfigGroup" overrideModeDefault="Allow" allowDefinition="Everywhere" />
The problem I am having is that when I open IIS Manager's Configuration Editor and select SimpleConfigGroup from the section drop down list it reports the following error:
"There was an error while performing this operation."
Details:
Filename: \\?\e:\sites\site1\web.config
Error:
However, if I remove the <sectionGroup> declaration from the site's web.config file I can edit the custom setting just fine using IIS Manager's Configuration Editor. However my web application can't run because the <sectionGroup> config info is required for the custom config section.
I've tried adding the <sectionGroup> to the root machine.config (and even dropping the configuration assembly into the .NET 2.0 framework assemblies folder) but I get the same error. I also tried signing the configuration assembly thinking there may be a trust issue but that hasn't helped either.
What I find strange is that the usual .NET Framework <configSections> in machine.config don't upset the IIS Manager Configuration Manager, e.g. for system.web yet my custom config sections do.
Why is this? Is it a bug in the Configuration Editor?
If anyone cares to try this here's the source to the SimpleConfigGroup and SimpleConfigSection classes:
SimpleConfigGroup.cs:
using System.Configuration;
namespace CustomSettingsLib
{
public class SimpleConfigGroup : ConfigurationSectionGroup
{
[ConfigurationProperty("SimpleConfigSection")]
public SimpleConfigSection SimpleConfigSection
{
get { return (SimpleConfigSection)this.Sections["SimpleConfigSection"]; }
}
}
}
SimpleConfigSection.cs:
using System.Configuration;
namespace CustomSettingsLib
{
public class SimpleConfigSection : ConfigurationSection
{
[ConfigurationProperty("MySetting", IsRequired = false)]
public string MySetting
{
get { return (string)this["MySetting"]; }
}
}
}
IIS7.5 configuration schema
Lloydz
2335 Posts
Microsoft
Re: ASP.NET custom config section breaks IIS Manager Configuration Editor
May 10, 2011 03:28 AM|LINK
Hi,
Thank you for providing detailed information. According to your description, the configuration seems to be correct. Have you tried iisreset to see if this address the issue?
Also please try to modify the setting as following to see if this work for you:
In your custom schema xml file:
Update it as:
<configSchema>
<sectionSchema name="SimpleConfigGroup/SimpleConfigSection">
<attribute name="MySetting" type="string" validationType="nonEmptyString" />
</sectionSchema>
</configSchema>
In applicationHost.config
Update it as:
<sectionGroup name="SimpleConfigGroup">
<section name="SimpleConfigSection" overrideModeDefault="Allow" allowDefinition="Everywhere" />
</sectionGroup>
Hope this helps.
Thanks.
kevin_k
8 Posts
Re: ASP.NET custom config section breaks IIS Manager Configuration Editor
May 10, 2011 12:50 PM|LINK
Hi Lloyd,
Thanks for the response. I actually arrived at the schema change you describe under my own steam after spelunking the ASPNET_schema.xml file and wondering why .NET's own <configSection> settings in machine.config didn't cause IIS Manager's Configuration Editor to choke. Then I noticed the use of <sectionSchema name="system.web/...">.
Also seems that you don't need to declare anything extra in applicationHost.config to allow the config editor to pick up this style of schema extension.
If you're bored you can read this question I also posted on Server Fault with my eventual progress to getting this working.
http://serverfault.com/questions/267556/asp-net-custom-configuration-section-declaration-breaks-iis-manager-configuration
I based my original schema extension on the guidance in this article:
http://learn.iis.net/page.aspx/242/extending-iis7-schema-and-accessing-the-custom-sections-using-mwa/
But have subsequently discovered this:
http://learn.iis.net/page.aspx/241/configuration-extensibility/
http://learn.iis.net/page.aspx/168/an-end-to-end-extensibility-example-for-iis-70-developers/
But hadn't realised that whilst these were describing extensions to the existing system.webServer schema definitions, it's also the style you need to use if you have your own schema extension that needs to be consumable by ASP.NET *and* the configuration editor GUI.
Thanks
Kevin