Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding final/effective web.config values (from inherited configurations)

Are there any apps that can show the final configuration as applied to a particular application directory? What I'm picturing is something along the lines of FireBug's CSS viewer.

Basically, it should show the equivalent single web.config file (as if you only had one), with all the values that apply to the directory in question, with each element (or even attribute) annotated with its source (the real .config file it came from).

This would greatly help deploying applications into foreign environments (eg, customer sites) where they sometimes have strange configs, that add in global includes (eg, they put the include in machine.config, instead of the web.config for that app) or have allowOverride=false, etc.

like image 703
gregmac Avatar asked Apr 25 '10 18:04

gregmac


2 Answers

If you know the config sections you are interested in then this will give you the effective settings as a class specifically for those settings. You could then cast the type and retrieve the settings that way and do the same for any sections you're interested in.

object vals = System.Configuration.ConfigurationManager.GetSection("AppSettings")

However, I don't know of any way to retrieve all of the current config sections if you want to discover all of the sections using code.

like image 29
Nate Zaugg Avatar answered Oct 27 '22 11:10

Nate Zaugg


None currently exist that are publicly known, however a viewer could easily be written. I would analyze reflected source of the .NET CLR regarding configuration inheritance and value determination. The code logic that calculates the final configuration for a domain is quite specific, so it makes sense no viewer currently exists for your request and this would be a good starting point for a viewer you envision.

Regarding making deployments, comparisons and editing config files easier, I personally recommend trying ASPhere. It's currently the best GUI editor for .NET config files, although it is not open source.

There are of course, additional helpful examples reading / accessing config files:

  • Setup and App config editor

  • Read/Write App.Config File with .NET 2.0

  • Using the Configuration Classes

  • Runtime Web.config / App.config Editing

And there are special exceptions for sections, such as "processModel" settings. For more information / overview details, see:

  • MSDN - ASP.NET Configuration File Hierarchy and Inheritance

  • MSDN - General Attributes Inherited by Section Elements

like image 151
sean2078 Avatar answered Oct 27 '22 11:10

sean2078