gpt4 book ai didi

asp.net-mvc - allowDefinition ='MachineToApplication' 错误设置 true

转载 作者:行者123 更新时间:2023-12-03 17:53:00 25 4
gpt4 key购买 nike

在我的 Asp.Net MVC 4 项目中,我在 .csproj 文件中设置了构建 View <MvcBuildViews>true</MvcBuildViews> .问题是构建项目时出现错误:
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.
我试图删除 obj 文件夹,但错误不断增加。错误指出问题出在身份验证标记行中:

<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

通常,我可以通过运行应用程序(我收到错误)、构建应用程序然后再次运行来运行应用程序。

最佳答案

执行@matrixugly 建议的操作将解决该问题,但也会导致编译时 View 检查也停止工作。我假设您仍然想在编译时错误检查您的 View ?如果是这种情况,请在下面进行更好的修复。

为了理解这些解决方案为何有效,我们必须首先了解问题是如何产生的:

  • 开发人员希望对 View 进行编译时检查,因此他们设置了 MvcBuildViews=true .
  • 应用程序构建良好,直到他们发布项目。
  • 后续尝试构建项目会导致编译时错误: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.

  • 那么是什么导致了这个问题呢?当项目发布编译器时,默认情况下它使用 <project-dir>\obj\放置它将使用的源文件的副本。不幸的是,这些文件在发布完成后不会自动删除。下次开发者用 MvcBuildViews=true 编译项目时,会报错,因为aspnet编译器包含 obj\编译期间的文件夹,因为它在 <project-dir> 下文件夹。

    那么我们如何解决这个问题呢?那么,你有四个选择:
  • 套装MvcBuildViews=false .我真的不认为这是一个解决方案,所以让我们继续。
  • 删除 <project-dir>\obj\ 中的文件.有效,但可能会很麻烦,因为它必须在每次发布后完成。
  • 通过使用 <BaseIntermediateOutputPath> 更改发布用作中间目录的路径项目配置文件中的属性。示例(引用:this link):
    <BaseIntermediateOutputPath>
    [SomeKnownLocationIHaveAccessTo]
    </BaseIntermediateOutputPath>
  • 在您的项目配置文件中添加一个新部分,在构建时为您删除有问题的文件(引用 Microsoft Connect)。我什至让你很容易,只需复制和粘贴:
    <PropertyGroup>
    <_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
    </PropertyGroup>
    <Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
    <ItemGroup>
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\Package\**\*" />
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TransformWebConfig\**\*" />
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\CSAutoParameterize\**\*" />
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TempPE\**\*" />
    </ItemGroup>

    <Delete Files="@(_TempWebConfigToDelete)"/>
    </Target>

  • 我的建议是使用选项 3 或 4。

    注意对于那些从未编辑过他们的项目文件的人,您无法在加载时对其进行编辑。必须首先通过右键单击它并选择 Unload Project 来卸载它。 .然后,您可以右键单击该项目并编辑该项目文件。或者,您可以在 Visual Studio 之外编辑文件。

    关于asp.net-mvc - allowDefinition ='MachineToApplication' 错误设置 <MvcBuildViews>true</MvcBuildViews>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12778088/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com