Why are there multiple (2) web.config files:
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.
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.
config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release. If you want to transform other files you can do that too.
The web.config in the Views directory just has one significant entry, which blocks direct access:
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
This is so someone cannot manually try to go to http://www.yoursite.com/views/main/index.aspx
and load the page outside the MVC pipeline.
What Silky said, except reworded.
In ASP .NET there is basically an inheritance style thing going on for config files. You have a machine.config out there in the .net framework folder which has basic settings for all apps on the machine. Anything you specify in a root web.config with the same tags would override the stuff in the machine.config.
Any web.config in a sub-folder can override or add additional settings within that sub-folder and its children.
It's always fun for me the first time one of my newer programmers puts in a http handler in a root folder and then all of the apps in the virtual directories under it explode because they don't have the DLL (they should have put the http handler statement only in the app that needed it, not in the root). :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With