views:

141

answers:

4

someone sent me over a link to download the sample standard asp.net mvc sample, i noticed that there were 2 web.config files

  1. 1 in the root directory
  2. 1 in the views directory

what is the reason for this?

+2  A: 

You can have multiple web.configs to define different settings for that folder. Used for permissions, and other such things.

Noon Silk
+7  A: 

The web.config in the Views directory just has 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.

Rex M
@Rex to which file i have to add my connection string
Pandiya Chendur
@Pandiya the root web.config, not one in the Views dir (or any other)
Rex M
+2  A: 

/Views/Web.config

This is not your application’s main web.config file. It just contains a directive instructing the web server not to serve any *.aspx files under /Views (because they should be rendered by a controller, not invoked directly like classic WebForms *.aspx files). This file also contains configuration needed to make the standard ASP.NET ASPX page compiler work properly with ASP.NET MVC view template syntax.

/Web.config

This defines your application configuration.

This is from the book Pro ASP.NET MVC Framework

San
+2  A: 

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). :)

Eric