开发者

Is there a way to not use the traditional .config files for ASP.NET?

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>

  &l开发者_如何转开发t;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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜