One Web.config in ASP.NET MVC instead of several for each Views folder

There are 5 areas in my ASP.NET MVC web application. Each area has its own folder Viewswith its own Web.configin it. This makes 6 configuration files along with the main one Web.configat the root of the application. This makes management difficult.

As far as I know, these configs do two things (at least by default):

1.) Install the Razor factory host to enable the selected default namespaces.

2.) Block direct access to files in the folder Views, processing requests with HttpNotFoundHandler.

The code in all of these files is Web.configalmost identical for me, and it doesn't seem to me that this is a good way to manage these configurations. If I added more areas or ordered my code in more detail, I could get as many as 5 Web.configfiles. Why do I need so much? Is it not enough?

My thoughts on the points are as follows:

ad 1.) Can all these namespaces be imported once into the root file of an application Web.configor imported into a file _ViewStart.cshtml?

ad 2.) . It makes no sense to block access to all code files in all folders, and then use the opposite approach - that is, change folders with static files in them (for example Assets) for use StaticFileHandler? Basically, it seems to me that a safer approach is for me to whitelist files that are allowed to be read using StaticFileHandler, rather than to indicate which files should be processed using HttpNotFoundHandler.

Is this doable? Am I missing something? Has anyone encountered similar problems with too many files Views Web.config?

Thanks for answers.

+4
source share
1 answer

web.config Areas web.config 5 .

enter image description here

ASP.NET . MSDN - ASP.NET

+5

All Articles