Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have multiple web.config files in a single web project?

Tags:

.net

asp.net

I wanted to know that can I have 2 or more web.config files in my web project? If yes then how the compiler will check the connection string?

like image 678
Rahul Tripathi Avatar asked Oct 14 '12 12:10

Rahul Tripathi


People also ask

How many Web config files that can be there an?

There is no restriction to use the web. config file in the asp.net web application. You can have 1 Web. config file per folder .

Why are there two web config files in MVC?

So logically if the view folder and view (webpages) are accessible or can be requested by user then the basic MVC pattern and practice followed by Microsoft will be violated. This is prevented by adding a web. config and blocking access to view folder and files directly via user request or through URL.


2 Answers

You can have multiple configuration files in your project at the same level too. We do it like this. We have one main configuration file (Web.Config), then we have two more configurations files. App.Config and Database.Config. in App.Config we defined all the application level settings. in Database.Config we define all the database level settings. And in Web.Config we refer App.Config and Database.Config like this:

 <appSettings configSource="app.config">  </appSettings>  <connectionStrings configSource="database.config">  </connectionStrings> 

Also , you can have multiple web.config files in sub directories. Settings will be override automatically by asp.net.

like image 92
muhammad kashif Avatar answered Sep 20 '22 20:09

muhammad kashif


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.

enter image description here

For example if you have a application which has two modules lets say accounts and sales. You will create both these modules in a separate folder with each folder having separate config files.

Please do watch this facebook video which explains the same in a very demonstrative manner. Click here to watch , why do we need 2 web.config files in a application

like image 24
Shivprasad Koirala Avatar answered Sep 19 '22 20:09

Shivprasad Koirala