I want to include configuration for the Application Warmup module for IIS 7.5 in my application's web.c开发者_如何学Goonfig 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.config
transformation feature. Using transformations you can, in combination with the website 'Publish' tool, transform your web.config
and add/remove settings depending on whether you're doing a debug or release build.
For more information see:
Web.config Transformation Syntax for Web Application Project Deployment
How to: Transform Web.config When Deploying a Web Application Project
Scott Hanselman has a great demo of this feature:
Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong
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.config
files. When you build the project in VS you use a pre-built event swap in the correct web.config
file. I've used this technique before but Scott Hanselman (as always) has a nice worked example:
Managing Multiple Configuration File Environments with Pre-Build Events
If you're using MSBuild directly then you could use a build task to modify the web.config
files. There's an extension library available from the MSBuild Community Tasks Project which provides additional extensions to MSBuild to make these tasks easier. The XmlMassUpdate
task 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.
精彩评论