I want to include configuration for the Application Warmup module for IIS 7.5 in my application’s web.config file ( an <httpWarmup> element inside <system.webServer>)
This works fine when the module is installed, but if I want to deploy the application to a server without the module installed (e.g. IIS Express) I get
HTTP Error 500.19 – Internal Server
Error
The requested page cannot be
accessed because the related
configuration data for the page is
invalid.
Can this be done? Is there a setting to make IIS ignore extra elements in <system.webServer> that it doesn’t recognise?
Thanks
If you’re using Visual Studio 2010 then you can use the
web.configtransformation feature. Using transformations you can, in combination with the website ‘Publish’ tool, transform yourweb.configand add/remove settings depending on whether you’re doing a debug or release build.For more information see:
Scott Hanselman has a great demo of this feature:
This works with ASP.NET 2.0 and 4.0.
If you’re still using Visual Studio 2008 then it’s still possible to achieve this.
First off is to use a brute force approach and maintain multiple
web.configfiles. When you build the project in VS you use a pre-built event swap in the correctweb.configfile. I’ve used this technique before but Scott Hanselman (as always) has a nice worked example:If you’re using MSBuild directly then you could use a build task to modify the
web.configfiles. There’s an extension library available from the MSBuild Community Tasks Project which provides additional extensions to MSBuild to make these tasks easier. TheXmlMassUpdatetask is probably the task you’d want to use. I’ll be honest and admit that I’m only scratching the surface of MSBuild at the moment and haven’t actually tried this, but (and I don’t mean this in a LMGTFY way) googling XmlMassUpdate returns a rich seam of useful looking hits.