![](/img/trans.png)
[英]“HTTP Error 500.30 - ASP.NET Core app failed to start” with IIS
[英]IIS .NET Core 5.0 MVC API - Getting HTTP Error 500.30 - ASP.NET Core app failed to start
已经尝试了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>
尝试了进程内和进程外,提供的环境变量没有区别。
代码部署到 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 函数来发送有关错误的电子邮件。 似乎他们造成了问题。 删除了所有谷歌东西的痕迹,不再需要几分钟才能开始。 我怀疑这是因为 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 消息,但至少错误是不同的。
我按照这些步骤https://dotnetblog.asphostportal.com/how-to-publish-asp-net-core-blazor-application-to-iis/和我的应用程序完美地工作。
好的,所以我在没有任何有用日志的情况下弄清楚了。
它不会运行 Google 身份验证这一事实让我开始考虑是否需要以自己的身份运行应用程序池,因此我将应用程序池身份设置为我的用户帐户。 没有骰子。 于是我找到了这篇文章: ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not
遵循他们的建议,现在应用程序报告开始正常。 我可以看到它正在运行的日志并且可以访问端点。
还能够为电子邮件通知添加回我的 Google 身份验证。 一切正常。
我还借此机会将应用程序池的超时设置为 0,并将其设置为启动模式:始终运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.