c# - ASP.net Core WebAPI 不在 IIS 后面启动
问题描述
我正在尝试托管一个 ASP.net Core WebAPI,就像 Microsoft Docs 告诉我的那样:在 ASP.NET Core 中托管
配置
我在 Windows Server 2016 上运行 IIS 10,其中安装了 Web Deploy 3.6、.Net Core Runtime 2.0.7 和 .NET Core Server Hosting Bundle。
Web API 配置如下:
程序.cs:
public static IWebHost BuildWebHost(string[] args) {
IConfigurationRoot config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.UseKestrel(opt => {
opt.Listen(IPAddress.Loopback, 4000);
})
.UseIISIntegration()
.Build();
}
网络配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Agent.DuZu.Web.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
在 IIS 上,ASP.net 核心模块被激活,我有一个绑定在端口 80 上的站点。
问题
我正在使用 WebDeploy 在服务器上发布应用程序,但应用程序无法启动。没有输出也没有错误。我不确定我是否遗漏了什么,或者我的配置是否失败。另外我想知道,是否有办法查看正在运行的应用程序。
解决方案
在同事的帮助下,我想出了解决方案:
权限:
IIS 必须对站点文件夹具有权限。必须检查 applicationpool 用户是否对文件夹具有权限。
我已在我所有站点所属的“C:\inetpub\sites”文件夹以及我正在使用的应用程序池上授予“本地服务”。
网络配置
WebDeploy 已覆盖 web.config 并将其更改为:
<aspNetCore processPath=".\Agent.DuZu.Web.exe"
arguments=".\Agent.DuZu.Web.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false" />
所以标准输出日志显示了一个参数错误。对此的解决方案是将 processPath 更改为“dotnet”,如本问题中所述。
<aspNetCore processPath="dotnet"
arguments=".\Agent.DuZu.Web.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false" />
另一件要提到的是,必须创建“日志”文件夹,因为 IIS 不会自己这样做。
推荐阅读
- javascript - 如何使用jquery在单击父行的+符号时切换子行?
- python - Python - 链接getter和setter时无法调用NoneType对象
- ios - SwiftUI 无法调整图片大小
- css - 为什么这个卡片翻转动画只有在第一次之后才起作用?
- android - Android Firebase 应用分发 - 服务凭证文件不存在。请检查服务凭据路径,然后重试
- php - Symfony/Doctrine:如何使 Doctrine 与 Unix 套接字一起工作?
- javascript - 显示来自 laravel validate 的响应 JSON 数据
- django - 使用 PyCharm 在 Docker 容器内使用 Django 运行测试用例时出错 (AppRegistryNotReady)
- typescript - 打字稿:对象键联合的类型不能用作该对象的键
- go - Gin-Gonic v1.4.0:缺少 ctx.FullPath()