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

asp.netWeb Config

asp.net Problem Overview


> 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 domain.com/web.config AND domain.com/portal/web.config ... so my domain.com/portal/default.aspx 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!

asp.net Solutions


Solution 1 - asp.net

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.

Solution 2 - asp.net

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.

Solution 3 - asp.net

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.

Solution 4 - asp.net

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.

Solution 5 - asp.net

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.

Solution 6 - asp.net

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.

Solution 7 - asp.net

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" />
</Target>

Hope this helps

Solution 8 - asp.net

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

Solution 9 - asp.net

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

Solution 10 - asp.net

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, https://connect.microsoft.com/VisualStudio/feedback/details/779737/error-allowdefinition-machinetoapplication-beyond-application-level

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.

Solution 11 - asp.net

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

Solution 12 - asp.net

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

Solution 13 - asp.net

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.

Solution 14 - asp.net

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.

Solution 15 - asp.net

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!!

Solution 16 - asp.net

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

from vs: Build > Clean Solution

then Rebuild.

Solution 17 - asp.net

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 : http://scottonwriting.net/sowblog/archive/2010/02/17/163375.aspx

Solution 18 - asp.net

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.

Solution 19 - asp.net

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.

Solution 20 - asp.net

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.

Solution 21 - asp.net

Check the path of the web.config that opens if click on error. Some node_modules, (node_module\selenium_webdriver\lib\test\data\web.config), also can have web.config file.

Solution 22 - asp.net

Delete obj and bin directly with fix that issue immediately.

Solution 23 - asp.net

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.

Solution 24 - asp.net

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.

Solution 25 - asp.net

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.

Solution 26 - asp.net

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.

Solution 27 - asp.net

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

Solution 28 - asp.net

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

Solution 29 - asp.net

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

Solution 30 - asp.net

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

From:

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

To:

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

Solution 31 - asp.net

I have encountered this error, and realised I'd inadvertently caused this error myself.

I had recently made some changes to my web.config file, and for ease at the time I'd copied the web.config file into a /backup/ folder in my project before I'd made the changes.

By removing this file from the /backup/ folder the error was resolved.

In practise I suppose it's no different to another contributor's comments about deleting the entire Debug folder.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJason WeberView Question on Stackoverflow
Solution 1 - asp.netbenni_mac_bView Answer on Stackoverflow
Solution 2 - asp.netAaroniusView Answer on Stackoverflow
Solution 3 - asp.netMatthew BrownView Answer on Stackoverflow
Solution 4 - asp.netLord of ScriptsView Answer on Stackoverflow
Solution 5 - asp.netRY4NView Answer on Stackoverflow
Solution 6 - asp.netTim CView Answer on Stackoverflow
Solution 7 - asp.netRikView Answer on Stackoverflow
Solution 8 - asp.netbenView Answer on Stackoverflow
Solution 9 - asp.netHugoView Answer on Stackoverflow
Solution 10 - asp.netPat Long - Munkii YebeeView Answer on Stackoverflow
Solution 11 - asp.netsudhAnsu63View Answer on Stackoverflow
Solution 12 - asp.netnPcompView Answer on Stackoverflow
Solution 13 - asp.netMartin SmellworseView Answer on Stackoverflow
Solution 14 - asp.netMikhail.GorbulskyView Answer on Stackoverflow
Solution 15 - asp.netFabianValView Answer on Stackoverflow
Solution 16 - asp.netkennydustView Answer on Stackoverflow
Solution 17 - asp.netSubodh PradhanView Answer on Stackoverflow
Solution 18 - asp.netTrungView Answer on Stackoverflow
Solution 19 - asp.netBaqer NaqviView Answer on Stackoverflow
Solution 20 - asp.netJosh HarrisView Answer on Stackoverflow
Solution 21 - asp.netIHAFURRView Answer on Stackoverflow
Solution 22 - asp.netMuhammad AdnanView Answer on Stackoverflow
Solution 23 - asp.netHammad KhanView Answer on Stackoverflow
Solution 24 - asp.netsojim2View Answer on Stackoverflow
Solution 25 - asp.netJohnCView Answer on Stackoverflow
Solution 26 - asp.netGuy SchalnatView Answer on Stackoverflow
Solution 27 - asp.netkrilovichView Answer on Stackoverflow
Solution 28 - asp.neteaglei22View Answer on Stackoverflow
Solution 29 - asp.netAhmed Mahmoud AbdElbasetView Answer on Stackoverflow
Solution 30 - asp.netKarsonView Answer on Stackoverflow
Solution 31 - asp.netAdam92View Answer on Stackoverflow