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

It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level.

The top line in all of my aspx pages in my /portal/ directory has this error message, and I know it’s a common one. I have googled this error message to no end, and I see a lot of posts telling me to configure the /portal/ folder as an application in IIS (which I have), and more posts telling me I have nested web.configs (but none of the postings offer guidance toward a solution).

My setup is that I have a web.config in my root directory, and then I’m trying to make a company portal, in the /portal/directory. The /portal/ directory has its own (necessary) web.config.

My web.config line 50 is like this:

    <customErrors mode="Off" defaultRedirect="customerrorpage.aspx"/>
    <anonymousIdentification enabled="true"/>
    <authentication mode="Forms"/>
    <membership defaultProvider="MyProvider">

So I have AND … so my page will not load.

What is the real solution to this? Do I somehow find a way to merge my root web.config with my /portal/ directory web.config, or am I way off base here?

Any guidance would be greatly appreciated!


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.NetFrameworkversionCONFIG 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.


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.

Method 2

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 myWebAppobjDebug and myWebAppobjRelease directories. I also needed to set a default startup page. But, then the app then started up fine. HTH.

Method 3

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.

Method 4

It was also happening on my home computer but ONLY when I enabled Build Views on the release configuration AND built a Release configuration. Otherwise it didn’t happen.

Though the Build Views option is very nice I ended up disabling it because this “error” would always pop up and let me unable to run the app.

Method 5

Just to say

If you Upgrade(eg 2008 -> 2010) A project Visual studio will create a backup (if you allow it) in the project solution which is added to the new solution, The old Webconfig is where the error pointed out above can then emanate from.

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.“@benni_mac_b

To Fix it: Just remove the backup folder from the project and solution, in this scenario.

Method 6

I have come up with another possible reason that this occurs.

I had an older web application built in 2.0. I migrated it to a 4.5 solution.

The application built and debugged just fine when inside of Visual Studio, but then when I attempted to Publish the web application, this error occurred over and over.

I finally discovered the problem was that Build Action for the web.config file was “Embedded Resource” rather than “Content”. Also, the Copy To Output Directory was set to “Always Copy” rather than “Do not copy”. I do not know when these settings were made, but I believe it was back in the 2.0 version of the application.

Modifying the settings for the web.config file allowed the Publish action in Visual Studio 2012 publication to work flawlessly.

Method 7

I had the same problem in an MVC project. The error occurred when I tried publishing. Turned out the obj folder should be empty (or at least not contain any web.config).

Running Clean didn’t do the trick for me.

I solved the problem by cleaning the obj folder before any build (building of the project won’t take that long anyway in my case).

I unloaded the project, and added the following to the BeforeBuild Target

<Target Name="BeforeBuild">
    <Delete Files="$(SolutionDir)$(ProjectDir)bin***.*" />
    <Delete Files="$(SolutionDir)$(ProjectDir)obj***.*" />
    <RemoveDir Directories="$(SolutionDir)$(ProjectDir)bin" />
    <RemoveDir Directories="$(SolutionDir)$(ProjectDir)obj" />
    <Message Text="Clean obj/bin from web project" />

Hope this helps

Method 8

“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.”

I had this problem in VS.NET. Turned out that when I was configuring some config transforms I had mistakenly set the Web.config file’s property “Copy always”. I usually set my transform files to “Copy always” but leave the web.config root file as “Do not copy”.

Watch out tho, because changing the properties of web.config also changes all the nested transforms.

So, to fix:

1) Change web.config to “Do not copy”

2) Optionally, if you’re using config transforms, set them to “Copy always”

3) Delete the obj and bin folders from the solution (these may not be visible so select the project node in Solution Explorer and click the “Show all files” toolbar button.

4) Publish

Worked for me.

Method 9

I experienced this error only during publishing of the application.

The properties of the web.config (and transformations) files were set as:

  • Build Action - None
  • Copy to Output - Always.

The solution was to change the settings to:

  • Build Action - Content
  • Copy to Output - Do not Copy

Method 10

I also had this issue and it came about after i used the Publishing Wizard to publish my site to the web.

After much digging around I came across this Bug report on the Connect website,

An MS rep replied and as well as explaining why this was a problem that occured when publishing he also included a temporary workaround that fixed the issue for me.

Method 11

Delete and create the virtual Directory again.
Right Click and Convert the virtual Directory to “Application

Method 12

Click on the Web.config file from Solution explorer and right click “Properties” and change to “Copy to Output Directory: Do not copy”.

enter image description here

Method 13

Here is another reason – If you copy your entire web app into one of its own sub-folders, you will get this error. I managed to do this to an old site when copying from one machine to another – just been asked to look at the site after a gap of about 2 years and the error occurred. Took a fair bit of figuring out – as I had no multiple config files.

Method 14

For me the reason was that the obj folder was under the web site folder and multiple web.config appeared after building different configurations. I solved the problem under vs2012 by movong the obj folder out from the web site. To do this I’ve added manualy (in the notepad) $(SolutionDir)Obj$(Configuration)
to every configureation in the web site project file.

Method 15

I was having the same issue when I would publish the site, if I build the site I get no issues but while publishing I would get this awful error:

“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”

I tried everything that has been stated here in this post to no resort, what worked for me was to just create a new publish profile with exactly the same as the one I’ve been using and that works well, don’t get the error with the new profile but do with the old. Not sure what the difference is but at least I can publish my MVC project.

Hope this helps somebody!!

Method 16

I had this issue, and resolved by cleaning my solution of old assemblies etc.

from vs:
Build > Clean Solution

then Rebuild.

Method 17

Windows start -> open Sites -> IIS -> right click your site -> Manage Web Site -> Advance Setting -> browse Physical Path -> try to select sub-folder of the once you are selection currently.

the logic is that the web config file inside the subfolder is trying to make changes and this is not permitted, has to be the selected folder :

Method 18

I also get this error when try to deploy a sub website in website.

The solution is:

  1. You must remove some config tabs like: profile, membership, roleManager, sessionState in the sub web.config
  2. Change Authentication to None as: <authentication mode="None" />
  3. And go to IIS right click on sub folder > Add Application.
  4. Reset IIS to resolve this issue.

IF get other issue don’t hesitate ping me, maybe I will find to help.

Method 19

It was fine on localhost but when I published a release on the server, I started the same error for few pages.
Then I cleaned up the solution and rebuild & published, things got fixed.

Method 20

I received this error on localhost in Visual Studio 2017, and a simple restart of Visual Studio cleared the issue.

I realise this issue can also be caused by having more than one web.config; one within a sub-folder for example. if you do have multiple web.config files purposely for another application: ensure the directory is not being seen as a virtual directory.

Method 21

Check the path of the web.config that opens if click on error. Some node_modules, (node_moduleselenium_webdriverlibtestdataweb.config), also can have web.config file.

Method 22

Delete obj and bin directly with fix that issue immediately.

Method 23

Make sure you dont’ fall in trap of accessing your local site wrong via localchost/mysite.test which should be mysite.test which will give you this error.

When you access your site like localhost/dir_name, in this case, your web.conf falls below root level and hence this error.

Method 24

I was migrating apps and the app had multiple apps(multiple web.configs) within it.. what I did was go into IIS then right click on the sub folders then “Convert to Application” and it worked.

Method 25

I got this error differently than everyone else:

I was migrating from vs2010 with web deployment project to vs2012 and a new web publish profile.

I created a new web publish project in vs2012 to publish to file system (we have a separate installer builder this is a commercial app) and I was publishing to a folder that was inside the existing web project which is linked to IIS.

This caused the error during publish which mystified me at first because I was publishing to file system, not IIS (I thought).

Solution was to change the publish to folder to outside the web project.

Method 26

Sometimes, the simple answer is best. I had two web.config files in my project. The one at the main level is where I needed to make the change to deal with my session timeout (which triggered this issue). I had a separate config file in my Razor Views directory, which had settings for Razor and its views. I was adding a section in there (not at the application level!). Without realizing I had two separate web.config files, I tried everything except looking for the obvious.

Method 27

my mistake was accidentally copy pasting a web.config inside another folder on the web server

Method 28

I got this error when I forgot to convert the published project into an application within IIS.

Method 29

In my case
I found that i have another Web.config file at old folder inside web application
I just delete the old web.config file and every thing is OK

Method 30

Comparing a project that was working to the one that had the above issue I made the following change. This resolved my issue.


  <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />


  <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x