I’m having some problems with deploying my application and while troubleshooting, I came across the Web.Config file in the Views folder. In an attempt to narrow down the possibilities of sources to my problem, I tried to find out the purpose of that Web.Config file but can’t really find much information.
So basically my questions are:
- What does the
Web.configfile do in theViewsfolder of a MVC project? - Is it required?
In ASP.NET webforms, I believe that to use a separate web.config file in a folder, that folder has to be set as a virtual folder in IIS. Is this the case in MVC (i.e. does the Views folder need to be configured as a virtual folder)?
No, you do not need to configure a virtual folder because of this extra
web.configfile.The
web.configfile exists in theViewsfolders to prevent access to your views by any means other than your controller. In the MVC design pattern, controllers are supposed to route requests and return a rendered view to the calling client.In other words, your view at
www.mydomain.com/MySuperController/AwesomeAction1/SweetPage.aspxshould not be directly accessible.If you peek at the
web.configfile it actually registers theHttpNotFoundHandlerto all paths and verbs:Or, in IIS 7 it might look like