我有一个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调用应该处理Controller方法,其所有逻辑与IIS一样。
我得到了它
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文件夹上面或只是一个文件夹。现在它有效。