首页 > 解决方案 > 通过 Azure Pipelines 将 .NET Core Web 应用程序部署到 IIS 服务器时出现 500 错误

问题描述

我正在使用我的项目AzureDevOps作为CI&CD工具。我使用了名为IIS website deployment. 我已经完成了配置并且运行良好。它可以成功部署。但是当我查看它时,我只能得到一个 500 错误。

端口 80(上面没有站点):

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

8000端口(我部署了我的站点并打开了防火墙访问):我无法获取任何像500左右的页面,ERR_EMPTY_RESPONSE浏览器上只有一个。

这是构建代码的目标文件夹的屏幕截图 截屏

web.config.xml web.config.xml

我在 Startup.cs 或 Program.cs 中是否遗漏了任何代码?我将它们保留为默认值。

标签: iis.net-coreazure-devopsazure-pipelinescontinuous-deployment

解决方案


要在 IIS 后面运行 ASP.NET Core 应用程序,您需要先安装托管包。

该捆绑包安装 .NET Core 运行时、.NET Core 库和 ASP.NET Core 模块。该模块允许 ASP.NET Core 应用程序在 IIS 后面运行。

在这里下载:

https://www.microsoft.com/net/permalink/dotnetcore-current-windows-runtime-bundle-installer

更多信息,参考:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#install-the-net-core-hosting-bundle

安装此托管包后,尝试运行dotnet ./yourdll.dll以测试您的 .NET Core 应用程序是否可以直接启动并准备好处理 HTTP 请求。默认情况下,ASP.NET Core 应用程序将启动并侦听端口 5000。

当您的应用程序准备就绪后,将其部署到您的 IIS 文件夹。像这样写你的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=".\YOUR_DLL.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

并尝试从 IIS 访问它。


推荐阅读