【发布时间】: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