Friday, September 07, 2012

Duplicate Section Defined in Web.config

I looked into a web.config parsing error which troubled me on one web server and not another...

It was an ASP.net web application with elements of .Net 2 but compiled under 3.5.   The app would compile fine but upon publishing the app there would be config errors. The particular error depended on if you were in the IDE or IIS7.  In IIS 7 the app would load and run fine but would not allow you to edit any site settings without throwing a "duplicate script section" error.  Basically it was implying that the script attribute had already been defined.

After finding that there was no duplicate and that all the tags were closed properly I checked it with another IIS instance and it worked fine.  This told me that it was probably related to the framework version on the app pool.

I right-clicked the site name in IIS, clicked Manage Application and picked Advanced Settings...

Then I clicked Application Pool and changed it from "Classic .Net App Pool" (framework 4.0) to ASP NET V2 Integrated.  (I used Integrated rather than V2 Classic because the script tag definitions in question called for Integrated mode)

Immediately the site settings like authentication etc. were editable in IIS without throwing errors.

So if you have a similarly impossible configuration error in IIS, check your framework version since xml tag implementations can differ from version to version... each framework "sees" the Web.Config file in a different context and may not understand some settings or choke on deprecated settings.