AspNetCoreModuleV2 问题 .NET Core 3.0

AspNetCoreModuleV2 issue .NET Core 3.0

希望有人能帮助解决这个问题:

我已经在 Azure 上部署了我的 .NET Core 3.0 应用程序,尽管它显示 "Publish Succeeded." 应用程序未加载(http 500,服务器错误)。 Azure 中的 "Diagnose and solve problems" 选项卡指向模块 "AspNetCoreModuleV2",如图所示 Azure - Diagnose and solve problems

我试过:

这是我当前的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.1.0-preview1-final" />
  </ItemGroup>

</Project>

这是我的 web.config 文件的样子

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\SportsStore.dll" stdoutLogEnabled="false" stdoutLogFile="\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 3f1b616a-5c07-4b23-9c86-ec6506dc3fa7-->

顺便说一句,应用程序在本地机器上运行没有任何问题

非常感谢能为我指明正确方向的任何帮助。

检查 PublishProfiles 文件夹(在 Properties 内)并确保您拥有 :

<SelfContained>true</SelfContained>

A self-contained application distributes the runtime with the application.

您可以尝试直接在 Azure 上更改 web.config,因此当您部署应用程序时,转到 web.config 并将 AspNetCoreModuleV2 替换为 AspNetCoreModule。直接更改 web.config 将重新启动应用程序轮询,以了解问题所在。

请参阅同一篇文章以及可能的解决方案:

我试过以 "self-contained" 的身份发布并修改 web.config,但是,没有任何效果。

经过进一步研究,我发现了 Azure 中的 "App Service Editor" 工具。查看输出错误后,我意识到问题与数据库防火墙阻止 "my" IP 有关。我之前用我的 IP 添加了一个规则,但是,由于某种原因,错误消息中显示的 IP 与我的实际 IP 不同。一旦我用这个 IP 在数据库上添加了另一条规则,它就会立即起作用。

另一个奇怪的是,"Diagnose and solve problems"工具(AspNetCoreModuleV2)报告的错误与实际问题没有太大关系。

感谢大家花时间回答我的问题。

编辑您的 csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <AspNetCoreModuleName>AspNetCoreModuleV2</AspNetCoreModuleName>
..

dotnet publish 期间,TransformWebConfig 任务以这种方式将您的 web.config 转换如下,这也适用于 Azure WebApp

<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\assembly.dll" hostingModel="OutOfProcess" />
    </system.webServer>
  </location>
</configuration>

在 Azure WebApp 中,HTTP Error 500.31 - ANCM Failed to Find Native Dependencies 错误似乎是由 InProcess 托管模型和模块 AspNetCoreModuleV2

引起的