【问题标题】:Why I get a 500 only on kestrel?为什么我只在红隼上得到 500?
【发布时间】:2019-08-24 00:12:33
【问题描述】:

我有一个 ASP.NET Core 2.0 WEB-API,它应该可以在 kestrel 上工作,因为它会在那里托管。当我从 Kestrel 开始时(请看下面的 launchSettings),有一个 POST 并且我总是得到 500 返回而不进入代码。意味着我到处都留下断点,当我在 Swagger 中执行 POST 时,没有命中断点。当我改用 IIS 时,它工作正常。 500 马上就来了。在 Linux Kestrel 上部署后也有 500 个。

我实现了@Startup.cs:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.Use((context, next) =>
        {
            context.Response.Headers.Remove("Server");
            return next();
        });

@Program.cs:

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://0.0.0.0:5000")
            .UseIISIntegration()
            .UseApplicationInsights()
            .UseKestrel()
            .Build();

@launchSettings.json:

"Kestrel": {
  "commandName": "Project",
  "launchBrowser": true,
  "launchUrl": "",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}

使用 Kestrel,POST 调用应该处理 Controller 方法,其所有逻辑与使用 IIS 相同。

【问题讨论】:

    标签: c# linux asp.net-web-api .net-core-2.0 kestrel


    【解决方案1】:

    我可以使用它

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseIISIntegration()
                .UseApplicationInsights()
                .UseKestrel(options =>
                {
                    options.Listen(IPAddress.Parse("0.0.0.0"), 5000);
                })
                .Build();
    

    和启动设置:

        "CZKestrel": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:59883/"
    }
    

    用于本地调试。

    为了让它作为服务工作,我做了 dotnet restore 和 dotnet build,我只将带有创建的 dll 的文件夹复制到另一个地方,然后运行/启动服务。我想当我启动它时,我应该在 dll 文件夹上方或仅位于其中的一个文件夹中。现在可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      • 2010-12-19
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多