Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the Web.Config file do in the views folder of a MVC project

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:

  1. What does the Web.config file do in the Views folder of a MVC project?
  2. 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)?

like image 940
Ola Karlsson Avatar asked Jun 01 '11 16:06

Ola Karlsson


People also ask

What is the use of Web config in MVC?

web. config file is an XML-based configuration file used in ASP. NET-based applications to manage various settings that are concerned with the configuration of our website. In this way, we can separate our application logic from configuration logic.

What is the purpose of web config file?

The Web. Config file is used to configure Oracle Web Application functionality. This file is typically installed in the c:\Inetput\wwwroot\WebApp directory. This section describes settings in the top-level WebApp Web.

Where is the web config file located in MVC?

The Machine. config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder. The default settings that are contained in the Machine.

What are the config files in MVC?

config file in MVC application is managed by the NuGet which will keep track of what packages and versions have installed within your application. The Web. config file of an MVC application is one of the most useful and important files which contains the application level configurations.


1 Answers

No, you do not need to configure a virtual folder because of this extra web.config file.

The web.config file exists in the Views folders 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.aspx should not be directly accessible.

If you peek at the web.config file it actually registers the HttpNotFoundHandler to all paths and verbs:

<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> 

Or, in IIS 7 it might look like

<add name="BlockViewHandler" path="*.aspx" verb="*"      preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/> 
like image 191
David Fox Avatar answered Sep 21 '22 10:09

David Fox