【问题标题】:IIS .NET Core 5.0 MVC API - Getting HTTP Error 500.30 - ASP.NET Core app failed to startIIS .NET Core 5.0 MVC API - 出现 HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动
【发布时间】:2021-12-13 03:58:26
【问题描述】:

尝试了HTTP Error 500.30 - ASP.NET Core 5 app failed to start 和其他类似帖子中的建议,但运气不佳。

我的 API 在 VS2019 中与 IIS Express 一起运行非常好,但发布后它就无法启动。

这是我的 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=".\MyApi.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

inprocess和outprocess都试过了,提供的环境变量没有区别。

代码部署到 C:\inetpub\wwwroot\MyApi

IIS_IUSRS 已被授予对 wwwroot 文件夹的读/写权限

这是我在 VS 项目中的工作午餐settings.json 文件

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44307",
      "sslPort": 44307
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyApi": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

这是我的程序.cs

public class Program
{
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                _ = webBuilder.UseStartup<Startup>();
            })
            .ConfigureServices(services =>
            {
                _ = services.AddHostedService<MyApiWorker>().Configure<EventLogSettings>(config =>
                {
                    config.LogName = "My API";
                    config.SourceName = "My API";
                });
            });

    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }
}

/inetpub/logs/logfiles 中的 IIS 日志并不是那么有用(4443 是我添加到 IIS 时使用的端口)。

#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2021-10-27 09:31:01
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2021-10-27 09:31:01 ::1 GET / - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 4
2021-10-27 09:31:07 ::1 GET / - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 0
2021-10-27 09:32:39 ::1 GET /swagger - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 0
2021-10-27 09:36:45 ::1 GET / - 4443 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/95.0.4638.54+Safari/537.36 - 500 0 2147500037 0

任何想法将不胜感激。我似乎找不到任何有意义的日志,并且应用输出的日志从不发布任何内容。

编辑:应用程序池没有托管代码 已安装 dotnet-hosting-5.0.11-win.exe 并多次重启和重启 IIS。

事件日志显示: 物理根目录为“C:\inetpub\wwwroot\myapi”的应用程序“/LM/W3SVC/1/ROOT”无法加载 coreclr。异常消息: 托管服务器在 120000 毫秒后未初始化。

EDIT 2现在在事件日志中得到这个:

The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID 
{3480A401-BDE9-4407-BC02-798A866AC051}
 and APPID 
{30AD8C8E-AE85-42FA-B9E8-7E99E3DFBFC5}
 to the user IIS APPPOOL\DotNetCore SID (S-1-5-82-2530134163-791093599-2246298441-3166710890-3969430272) from address LocalHost (Using LRPC) running in the application container Unavailable SID (Unavailable). This security permission can be modified using the Component Services administrative tool.

所有标准输出记录 0kb 空文件

编辑 3 我也可以通过双击exe进入文件夹并运行它,但由于某种原因,IIS不会。这是没有意义的。我得到的只是这个错误:

Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi\' failed to load coreclr. Exception message:
Managed server didn't initialize after 120000 ms.

延长超时也无济于事,手动执行时需要几秒钟才能启动和运行。

编辑 4 我在 API 中有一些 Google Gmail 功能可以发送错误电子邮件。似乎他们造成了问题。删除了谷歌东西的所有痕迹,不再需要几分钟才能启动。我怀疑这是因为 Google 试图让 IIS 接受使用 Gmail 的条款,但这显然不可能发生。

现在已经解决了,我仍然收到一个新错误:

Application '/LM/W3SVC/1/ROOT' with physical root 'C:\inetpub\wwwroot\myapi\' has exited from Program.Main with exit code = '0'. Please check the stderr logs for more information.

但是没有找到stderr消息,但至少错误是不同的。

【问题讨论】:

  • 事件查看器中的任何内容,最有可能在 Windows 日志/应用程序下?
  • 您的应用程序池是什么样的?
  • 您是否将 .NET CLR 版本设置为无托管代码?
  • @gunr2171 是的。在上面添加。没多大用处。

标签: c# asp.net-mvc asp.net-core-5.0


【解决方案1】:

我能够在我的 Windows IIS 上进行托管。

先决条件:您需要在服务器上安装 .Net Core Hosting Bundle。

在 IIS 管理器中,

  1. 在 IIS 中创建新网站并指向您发布代码的文件夹。 IIS Website

  2. 创建网站时,会自动创建在 ApplicationPoolIdentity 上运行的应用程序池。确保 .Net CLR 版本为“无托管代码”app pool

  3. 重置 IIS

浏览应用网址:http://:port/

【讨论】:

  • 我已安装 dotnet-hosting-5.0.11-win.exe 应用程序池没有托管代码
【解决方案2】:
  1. 请确保您已在服务器上安装了 .net 核心
  2. 将您的应用程序池设置为无托管代码
  3. 如果还是不行,请检查错误日志

我按照这些步骤https://dotnetblog.asphostportal.com/how-to-publish-asp-net-core-blazor-application-to-iis/ 操作,我的应用程序可以完美运行。

【讨论】:

  • 谢谢,但我已经完成了所有这些。我已经分享了我拥有的错误日志。这不在服务器上。它在 IIS Express 版本工作的同一台 Windows 机器上。
  • 顺便说一句,我的是核心 5,不是 3.1,也不是 Blazer
  • PS:所有stdout日志都是0kb的空文件
  • .net core 3 或 5 的部署相同。
  • 不是同一个主机包。
【解决方案3】:

好的,所以我发现它没有任何有用的日志。

它不会运行 Google 身份验证的事实让我开始考虑是否需要以自己的身份运行应用程序池,因此我将应用程序池身份设置为我的用户帐户。没有骰子。于是我发现了这个帖子:ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not

按照他们的建议,现在应用程序报告开始正常。我可以看到它正在运行并且可以到达端点的日志。

还能够为电子邮件通知添加我的 Google 身份验证。一切正常。

我还借此机会将应用程序池的超时设置为 0,并将其设置为启动模式:始终运行。

【讨论】:

    猜你喜欢
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 2023-01-09
    • 2022-10-01
    • 2021-12-08
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多