c# - ASP.net Core WebAPI 不在 IIS 后面启动

标签 c# iis asp.net-core iis-10

我正在尝试托管一个 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/

相关文章:

c# - 压缩文件夹后所有 zip 条目更改编码

c# - INSERT INTO 语句中的语法错误

java小程序运行本地主机但在发布iis后不运行,作者:asp.net

asp.net-mvc - 应用程序每15分钟编译一次

c# - 在两个模型或 Razor 页面之间传递 ID

c# - 如何在 Restful 响应中保持区分大小写?

c# - 如何在 C# 中对继承的基构造函数执行操作?

c# - 如何在 C# 中读取已编译的资源 (.res) 文件?

C# Console.WriteLine 不是从方法调用的

c# - 在 ASP.NET 中是否可以单独从 HTTP 请求的用户代理字符串派生浏览器 MajorVersion?