我正在尝试托管一个 ASP.net Core WebAPI,就像 Microsoft Docs 告诉我的那样:Hosting in 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 Core 模块已激活,我有一个绑定(bind)到端口 80 的站点。
问题
我正在使用 WebDeploy 在服务器上发布应用程序,但应用程序无法启动。没有输出也没有错误。我不确定我是否遗漏了什么或者我的配置是否只是失败了。 另外我想知道,是否有办法查看正在运行的应用程序。
最佳答案
在同事的帮助下,我找到了解决方案:
权限:
IIS 必须对站点文件夹具有权限。必须检查 applicationpool 用户是否具有文件夹权限。
我已经在我的所有站点所在的“C:\inetpub\sites”文件夹以及我正在使用的应用程序池上授予了“本地服务”。
web.config
WebDeploy 已覆盖 web.config 并将其更改为:
<aspNetCore processPath=".\Agent.DuZu.Web.exe"
arguments=".\Agent.DuZu.Web.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false" />
所以标准输出日志显示了参数错误。 解决方案是将 processPath 更改为“dotnet”,如 question 中所述.
<aspNetCore processPath="dotnet"
arguments=".\Agent.DuZu.Web.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="false" />
另一件需要提及的事情是,必须创建“logs”文件夹,因为 IIS 不会自行执行此操作。
关于c# - ASP.net Core WebAPI 不在 IIS 后面启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50016561/