Reputation:
Is there a way, in the web.config, to specify machine-specific values? For example: in production I want the <customErrors>
node to redirect to specific pages for displaying user-friendly error-handling pages, but in development, test, and staging, I want <customErrors mode="Off" />
so I can see as much detail as possible.
Is this currently possible?
Upvotes: 1
Views: 511
Reputation:
I'm writing and accepting my own answer because there isn't an answer to the question as I asked it. For the path:
C:\inetput\wwwroot
where wwwroot is relative root, my goal was to put the machine-specific instruction for <customErrors>
in the inetpub
directory so that XCopying new code automatically picked up established machine settings in the external config file. It might be possible to do this by editing the machine.config file, but that's too low-level of a solution (requires managers' signatures on paper before the server admins will do this).
So I'm simply going to stick with the status quo of editing the web.config files for the dev, test, and staging servers.
Upvotes: 1
Reputation: 26956
With ASP.NET 2 and above, a lot of the config elements now support a "configSource" attribute, that allows you to replace the contents of that section with an external file. this could allow you to have general settings in the main web.config and then separate files for the sections you know are going to change per environment.
As Nathan points out, in this instance you could use the RemoteOnly mode, which will display full errors when you are browsing the site on "localhost" - if you aren't developing on LocalHost then this won't help you.
VS2010 will add a new feature where you can modify the config file based on the build target, so a release or production build could automatically set this to "On", while debug or staging might set this to "Off".
Another option is to hook into the Application_Error event in the global.asax, and if the user is logged in as some sort of admin, output the stack trace, otherwise display the error page.
Upvotes: 2
Reputation: 1786
Isn't that what the .config files are for? Different configurations for different environments? With websites, we always have different web.configs for each environment (referencing different connection strings etc. . .) Nathan Taylors answer is correct for your specific problem though.
Upvotes: 0
Reputation: 4385
If you make
<customErrors mode="RemoteOnly">
then you will see detailed error messages on the Web Server machine but friendly error messages (that you will need to specfy in web.config) in all remote machines.
Upvotes: 0