为什么我在红est上只得到500?

时间:2019-04-02 15:40:35

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

我有一个 ASP.NET Core 2.0 WEB-API ,它应该可以在 kestrel 上运行,因为它将被托管在其中。当我从Kestrel开始时(请看下面的launchSettings),有一个POST,而我总是得到 500的返回而无需输入代码。意味着我到处都留有breackpoints,当我在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调用应以与IIS相同的逻辑处理Controller方法。

1 个答案:

答案 0 :(得分:0)

我了解了

    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还原和dotnet构建,即我仅将创建了dll的文件夹复制到其他位置,然后运行/启动该服务。我猜想当我启动它时,我应该在dll文件夹内或者只是其中一个文件夹。现在可以了。