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

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


我实现@Startup.cs:


    public void Configure(IApplicationBuilder app, IHostingEnvironment env)

    {

        app.Use((context, next) =>

        {

            context.Response.Headers.Remove("Server");

            return next();

        });

@程序.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 方法。


撒科打诨
浏览 139回答 1
1回答

慕的地10843

我得到它的工作&nbsp; &nbsp; public static IWebHost BuildWebHost(string[] args) =>&nbsp; &nbsp; &nbsp; &nbsp; WebHost.CreateDefaultBuilder(args)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .UseStartup<Startup>()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .UseIISIntegration()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .UseApplicationInsights()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .UseKestrel(options =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options.Listen(IPAddress.Parse("0.0.0.0"), 5000);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Build();和启动设置:&nbsp; &nbsp; "CZKestrel": {&nbsp; "commandName": "Project",&nbsp; "launchBrowser": true,&nbsp; "environmentVariables": {&nbsp; &nbsp; "ASPNETCORE_ENVIRONMENT": "Development"&nbsp; },&nbsp; "applicationUrl": "http://localhost:59883/"}用于本地调试。为了让它作为服务工作,我做了 dotnet restore 和 dotnet build,我只将带有创建的 dll 的文件夹复制到另一个地方,而不是运行/启动服务。我想当我启动它时,我应该在里面或 dll 文件夹上面的一个文件夹。现在可以了。
打开App,查看更多内容
随时随地看视频慕课网APP