Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

divide web.config

I am developing a asp.net project and I dont have very long web.config file yet(more then 400 lines). but with this nhibernate log4net and urlrewrites. its getting bigger and bigger. is there a proper way to divide web.config into pieces. like nhibernate.config and log4net.config ofcourse urlrewrite.config

like image 860
ozkanpakdil Avatar asked Jan 04 '10 03:01

ozkanpakdil


People also ask

Can we have 2 web config?

Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration. For example if you have a application which has two modules lets say accounts and sales.

How can I use two web config in one file?

You can have 1 Web. config file per folder . So in your root you can have a web. config and in a subfolder you can have another one that overrides settings from the one in the root.

Can we use multiple Web config in asp net?

For that question answer is Yes we can use multiple web. config files in single web application but how? By creating web. config file in sub root folders we can use multiple web.

Can we run a Web application without web config file?

Yes, you will be able to run an ASP.NET application without a WEB. CONFIG file in its root folder. If the application doesn't find a WEB. CONFIG file in its root folder, then it will take MACHINE.


2 Answers

system.webServer is a configuration section group - you cannot externalize that.

You can only put the configSource= on a configuration section - e.g.

<system.webServer>
    <validation configSource="validation.config"/>
    <modules configSource="modules.config" />
    <handlers configSource="handlers.config" />
</system.webServer>

What is a configuration section group or a regular configuration section can only be determined by looking at the documentation for those things (and even then it's often not very easy to figure out whether it's a section or a section group :-( ).

like image 133
marc_s Avatar answered Oct 06 '22 18:10

marc_s


This is possible by using the configSource attribute of root sections in the config file. This is actually a feature of the .NET configuration system so it can be done in any web or app config file.

Here is a blog post that describes this feature quite well.

like image 29
joshperry Avatar answered Oct 06 '22 18:10

joshperry