Error to use a section registered as allowDefinition='MachineToApplication' beyond application level

Just for background information; Configuration information for an ASP.NET website is defined in one or more Web.config files. The configuration settings are applied in a hierarchical manner. There's a “global” Web.config file that spells out the baseline configuration information for all websites on the web server; this file lives in the %WINDIR%\Microsoft.Net\Framework\version\CONFIG folder. You can also have a Web.config file in the root folder of your website. This Web.config file can override settings defined in the “global” Web.config file, or add new ones. Additionally, you may have Web.config files in the subfolders of your website, which define new configuration settings or override configuration settings defined in Web.config files higher up in the hierarchy.

Certain configuration elements in Web.config cannot be defined beyond the application level, meaning that they must be defined in the “global” Web.config file or in the Web.config file in the website's root folder. The <authentication> element is one such example. The above error message indicates that there is a Web.config file in one of the website's subfolders that has one of these configuration elements that cannot be defined beyond the application level.

Source: http://scottonwriting.net/sowblog/archive/2010/02/17/163375.aspx

You have correctly identified the 2 possible approaches.

1 - Depending on the contents of your second web.config and if your setup would allow (i.e same authentication method) - add the <authentication> settings and any other elements that should be define globally into the top web.config

2 - If you cannot merge then web.config contents then you should be able to turn the sub-folder into a web application in IIS by following the steps contained in this link archived link below. The original link is no longer working. (see archived) Hope this helps.


For what it's worth, I had received the error, "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level." and ended up resolving it by clearing the \myWebApp\obj\Debug and \myWebApp\obj\Release directories. I also needed to set a default startup page. But, then the app then started up fine. HTH.


As RY4N says above, it's not necessarily the web.config in your Project folder that causes the problem. In some cases I have found that running a build under the Debug profile will leave behind detritus in the Debug folder under the project in question. There is often a web.config file in here that leads to the error above when you subsequently run a build under the Release profile.

The solution that works for me here is to delete the entire Debug folder that the prior build(s) created under the project directory.