FIX: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS

Published 17 February 10 01:39 PM | Scott Mitchell

I teach two six week courses on ASP.NET at the University of California - San Diego Extension. The first class serves as an introduction to ASP.NET and as such many of the students create their first ASP.NET websites in class. During the first meeting students create a simple ASP.NET website. At the end of the first evening, those students who did not bring their own laptop need to work on their website from home or work; they may copy the files to a thumb drive or ZIP up the files and send them via email. In either case, it's not uncommon for students to bump into the following error when opening the website to bump into the following error message:

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

This error message isn't the most sensible error message, especially those to ASP.NET, so let me try to explain it.

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 than has one of these configuration elements that cannot be defined beyond the application level.

This problem most commonly arises when you open the website in Visual Studio but accidentally open the parent of the root folder. For example, imagine that you have a website located at C:\MyProjects\Website1, where the Website1 folder is the root of the website. When you open this website from Visual Studio you are asked to specify the website's root folder - it is imperative that choose the Website1 folder. If you accidentally select the MyProjects folder then the Web.config file in the Website1 folder is now in one of the website's subfolders. Because that Web.config file includes the <authentication> element, among other application-level settings, you'll receive the above error.

The fix to this error (in most cases), then, is to close your project and reopen it from Visual Studio, making sure that you select the appropriate folder.

Happy Programming!

Filed under:

Comments

# Darian Ross said on July 5, 2010 07:02 PM:

This error happens to me when I try to use an encryption strength in web.config that looks to IIS for it's RSA and MD5 settings.  I guess that means I need to set these web.config properties at the global level.  I'll have to give that a try and see if I can get by that error.

# Hari said on January 3, 2011 06:49 AM:

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.