Error to use a section registered as allowDefiniti

2019-01-02 18:01发布

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!

23条回答
查无此人
2楼-- · 2019-01-02 18:11

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

查看更多
时光乱了年华
3楼-- · 2019-01-02 18:12

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.

查看更多
高级女魔头
4楼-- · 2019-01-02 18:15

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.

查看更多
几人难应
5楼-- · 2019-01-02 18:16

Click on the Web.config file from Solution explorer and change

Copy to Output Directory = Do not copy

查看更多
春风洒进眼中
6楼-- · 2019-01-02 18:16

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.

查看更多
妖精总统
7楼-- · 2019-01-02 18:18

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

from vs: Build > Clean Solution

then Rebuild.

查看更多
登录 后发表回答