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