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:19

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
查看更多
低头抚发
3楼-- · 2019-01-02 18:19

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.

查看更多
余生请多指教
4楼-- · 2019-01-02 18:20

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.

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

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.

查看更多
无与为乐者.
6楼-- · 2019-01-02 18:24

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

查看更多
何处买醉
7楼-- · 2019-01-02 18:25

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.

查看更多
登录 后发表回答