ASP.net Core WebAPI 未在 IIS 后面启动

Ber*_*ger 4 c# iis iis-10 asp.net-core

我正在尝试托管 ASP.net Core WebAPI,就像 Microsoft 文档告诉我的那样: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();
}
Run Code Online (Sandbox Code Playgroud)

网络配置:

<?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>
Run Code Online (Sandbox Code Playgroud)

在 IIS 上,ASP.net Core 模块已激活,并且我有一个绑定在端口 80 上的站点。

问题

我正在使用 WebDeploy 在服务器上发布应用程序,但应用程序无法启动。没有输出也没有错误。我不确定我是否遗漏了某些内容或者我的配置是否失败。我也想知道是否有办法查看正在运行的应用程序。

Ber*_*ger 6

在同事的帮助下我找到了解决方案:

权限:

IIS 必须拥有站点文件夹的权限。必须检查应用程序池用户是否具有文件夹的权限。

我已在我的所有站点所属的“C:\inetpub\sites”文件夹以及我正在使用的应用程序池上授予“本地服务”。

网络配置

WebDeploy 已覆盖 web.config 并将其更改为:

<aspNetCore processPath=".\Agent.DuZu.Web.exe" 
    arguments=".\Agent.DuZu.Web.dll"
    stdoutLogEnabled="true" 
    stdoutLogFile=".\logs\stdout" 
    forwardWindowsAuthToken="false" />
Run Code Online (Sandbox Code Playgroud)

因此标准输出日志显示参数错误。解决方案是将 processPath 更改为“dotnet”,如本问题所述。

<aspNetCore processPath="dotnet" 
    arguments=".\Agent.DuZu.Web.dll"
    stdoutLogEnabled="true" 
    stdoutLogFile=".\logs\stdout" 
    forwardWindowsAuthToken="false" />
Run Code Online (Sandbox Code Playgroud)

另一件需要提到的是,必须创建“logs”文件夹,因为 IIS 不会自行执行此操作。