0

已尝试HTTP 错误 500.30 - ASP.NET Core 5 应用程序无法启动和其他类似帖子中的建议,但运气不佳。

我的 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 项目中的工作 lunchsettings.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 毫秒后未初始化。

编辑 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 功能可以发送错误电子邮件。似乎他们造成了问题。删除了谷歌东西的所有痕迹,不再需要几分钟才能启动。我怀疑这是因为谷歌试图让 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消息,但至少错误是不同的。

4

3 回答 3

0

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

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

在 IIS 管理器中,

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

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

  3. 重置 IIS

浏览应用程序 url:http://:port/<controllername/route>

于 2021-10-27T23:14:02.890 回答
0
  1. 请确保您已在服务器上安装了 .net 核心
  2. 将您的应用程序池设置为无托管代码
  3. 如果仍然无法正常工作,请检查错误日志

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

于 2021-10-28T07:01:27.707 回答
0

好的,所以我在没有任何有用日志的情况下弄清楚了。

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

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

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

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

于 2021-10-29T02:29:28.517 回答