2

I find Web.config xml pretty verbose.

Do you know any initiative made in the way to enable cleaner config files, using YAML, or .rb files, anything that could suck less?

EDIT: I already know that FubuMVC web framework, built on top of ASP.NET, tries to reduce a lot the amount of XML you need to put in that file in order to work properly. But it is still pretty ugly, I find it unnecessary:

<?xml version="1.0"?>

<configuration>

  <appSettings/>
  <connectionStrings/>

  <system.web>
    <compilation debug="true">
      <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <authentication mode="None" />
    <customErrors mode="RemoteOnly"/>
    <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
    </pages>
    <httpModules>
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </httpModules>
    <httpHandlers>
    </httpHandlers>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
    <handlers>
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>
  </system.webServer>

</configuration>

This is the bare minimum amount of XML you need to make things run, really bad. Many things above could just be the default.

7
  • I do care about my project code, including config files. If you see a rails config file, probably you will understand why do I care.. Jul 27, 2010 at 17:40
  • 4
    In ASP.NET 4.0 Microsoft already reduced quite some config code. 3.5 unfortunately was a burden. Jul 27, 2010 at 17:41
  • 1
    @Victor: this isn't Rails. It's ASP.NET, and the config files have been this way since version 1. If you waste time on this, you'll be one of the very few people who will. Jul 28, 2010 at 1:20
  • 1
    @John: I know it isn't rails, you don't need to say this to me. Not changing since version 1 for me isn't a quality neither, because things like this make ASP.NET loose the simplicity that many people want in current web frameworks. I JUST would like to know if there was a way to do this differently, a simple curiosity, so if you don't care about this maybe you shouldn't waste your time at this question being so rude. Jul 28, 2010 at 3:08
  • 1
    @John: I don't wish it was rails, I wish it was.. better, easier, not IDE-oriented, but I'll not be disappointed if things can't be like that. I'm not starting with ASP.NET neither, I've learned to deal with current reality some years from now. This was a exploration question, I would like to know if there is a way to do differently things, is this wrong or something? Instead of answering or contributing to the question, you've recurred to a fallacy ( known as "appeal to tradition" goo.gl/8Cyy ) to disqualify my question. Jul 28, 2010 at 11:18

2 Answers 2

6

My recommendation would be to leave Web.config alone as much as possible, and split your own configuration settings off into separate files.

e.g.

  <connectionStrings configSource="Configs\ConnectionStrings.config"/>
  <appSettings configSource="Configs\AppSettings.config"/>

Instead of having your connection strings and app settings inside Web.config.

1
  • 1
    +1. The config files should be left alone. The items that the developer actually cares about can/should be abstracted away into files as you've shown here.
    – p.campbell
    Jul 28, 2010 at 1:25
1

The minimum web.config can be much more smaller than that. As of .NET 4.0, the smallest is:

<?xml version="1.0"?> 
<configuration>
  <system.web> 
     <compilation targetFramework="4.0" /> 
  </system.web> 
</configuration>

Source: http://msdn.microsoft.com/en-us/library/s57a598e.aspx

2
  • this answer doesn't add a lot of value. What are your suggestions on how the OP can trim down his .config?
    – p.campbell
    Jul 28, 2010 at 1:26
  • 1
    The simplest web.config (as of .NET 4.0) is: <?xml version="1.0"?> <configuration> <system.web> <compilation targetFramework="4.0" /> </system.web> </configuration> Source: msdn.microsoft.com/en-us/library/s57a598e.aspx
    – Tundey
    Aug 10, 2010 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.