首页 > 解决方案 > 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 在服务器上发布应用程序,但应用程序无法启动。没有输出也没有错误。我不确定我是否遗漏了什么,或者我的配置是否失败。另外我想知道,是否有办法查看正在运行的应用程序。

标签: c#iisasp.net-coreiis-10

解决方案


在同事的帮助下,我想出了解决方案:

权限:

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 不会自己这样做。


推荐阅读