Cumbersomeness Web.Config

People who are in .NET arena might encounter the plethora of xxx.config files especially web.config.  It is a required devil for placing any configuration settings for your applications.  We should appreciate the effort taken by the engineers at Microsoft for introducing (at that time, Java’s configuration approach is very immature) and providing a declarative approach, centralized and optimistic way of configuring your .NET application of any size.  This has well fitted for applications written for simple purpose including training codes, in-house tools, etc.  In a real-world, irrespective of small, medium or large scale, both Visual Studio and developers place lots of stuff on this mess sourrounded by <, >, />, ” characters. 

When you see the web.config schema, it accomodates the following types of configuration for an application: 

  • Configuration section declaration (your custom configuration section)
  • Startup settings
  • Runtime settings such as impersonation, app domain manager, GC, CAS publisher policy, etc
  • Remoting settings
  • Network settings like authenticatio modules, proxy settings, System.Net, connection related
  • Tracing and debug
  • Application settings
  • Connection strings
  • ASP.NET settings like anonymous identification, authentication and authorization, caching, compiling, custom errors, health monitoring, HTTP runtime, handlers and modules, membership
  • WCF settings like service endpoint, service behavior and binding configurations

Bit sleepy?  Refer for WCF and for ASP.NET specific settings.  

There are machine wide settings those are overridden by site and application wide settings also.  Does this really prouductive in development stage and helpful in production stage?  Having experience on real world .NET applications, the main concerns with web.config are: 

  • Readability & Understandability.  Though it has the capability of defining the whole earth even the whole universe, readability is very bad.  Mentally, it outshines the content clarity.

Let us see a sample web.config for a WCF service.  How easy for you to add some more settings related to WCF tracing? 


The above configuration is for a federated WCF web service.
When you refer the alternate representations of XML, you can feel the readability issue.  Here is, an example JSON taken from Wikipedia: 

 "firstName": "John",
 "lastName": "Smith",
 "age": 25,
 "streetAddress": "21 2nd Street",
 "city": "New York",
 "state": "NY",
 "postalCode": "10021"
 "type": "home",
 "number": ""
 "type": "fax",
 "number": ""

The same in XML: 

21 2nd Street New York NY 10021

The same in YAML which is very famous in Rails arena: 

firstName:     John
lastName:      Smith
age:     25
    streetAddress:   21 2nd Street
    city:      New York
 state:     NY
 postalCode:      10021

    – type:   home
 - type:   fax

  • Managability – the user who might be a developer, solution architect, production administrator have to manage lot of stuff to accomplish an intent.  For example, WCF security related settings are scattered across service binding (security mode settings) and behavior (e.g. service credential settings) sections.  Thought technically this is the correct way, however from an user perspective, this has lesser managability.
  • Mixture Settings. since web.config is the only best place for any configuration, the “separation of concerns” principle couldn’t be achieved in various stages of configuration.  For example, some settings are more helpful during development stage, for example, the list of claims types can be understood by a WCF service, assemblies for handling custom authentication, etc.  But these configuration are no way helpful, but making this as configuration is harmful to the application at the production stage.  Just think that changing “GivenName” claim to “GivenName2″ in the above sample web.config might break the system.

What is expected?

Yes, we should appreciate the level of flexibility and extensibility available in .NET.  However, in the era of agile, productivity and simplicity are matters.  It is time to adopt and follow “convention over configuration” approach those are main part in Rails and Android development world.  If required, let the user (again developer or solution architect) override the convention. 

Instead of putting everything on the messy XML tags, provide developer/solution architect/administrator friendly DSL, which would be internal DSL on C# or easy to learn external DSL.  For example, in Rails, to map a web request to appropriate REST action is being configured by Ruby syntax.

ActionController::Routing::Routes.draw do |map|
 map.connect ‘products/:id’, :controller => ‘catalog’,
 :action => ‘view'

 #...other routings

In the above code, you see such mapping.  These kind of scripting will be more favourable than the awkwardness XML.

Share This: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg


  • Yogesh wrote:

    Yes Sir.

    I Agree with your comments. if we add 50 lines of code to web.config it becomes worse.

    They can also think about having #regions for logicall separatation in addition to the default sections.

    Respond to this
  • udooz wrote:

    Yes Yogesh

    Respond to this

Leave a Reply