已尝试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消息,但至少错误是不同的。