为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
撒科打诨 2022-11-22 15:10:28
我有一个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 方法。
查看完整描述

1 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

我得到它的工作


    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 文件夹上面的一个文件夹。现在可以了。


查看完整回答
反对 回复 2022-11-22
  • 1 回答
  • 0 关注
  • 59 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信