简体   繁体   English

禁用 https dotnet core 3.0 webapi

[英]Disable https dotnet core 3.0 webapi

For dotnet core 2.x I was able to modify the program.cs file to specify ports:对于 dotnet core 2.x,我能够修改 program.cs 文件以指定端口:

        public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://0.0.0.0:8080")
            .Build();

For dotnet core 3.0, the program.cs file is a little different and no matter what I do, I still get the https option.对于 dotnet core 3.0,program.cs 文件有点不同,无论我做什么,我仍然得到 https 选项。 The default program.cs file for dotnet core webapi has this: dotnet core webapi 的默认 program.cs 文件具有以下内容:

        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });

In the Windows command prompt, I've also tried dotnet new webapi --no-https in the command prompt and publishing and running the.dll it still listens on both http and https. In the Windows command prompt, I've also tried dotnet new webapi --no-https in the command prompt and publishing and running the.dll it still listens on both http and https. It looks like this option removes https from the launchSettings.json file.看起来此选项从 launchSettings.json 文件中删除了 https。 I am not using Visual Studio or any IDE, only the Windows Command Prompt.我没有使用 Visual Studio 或任何 IDE,只有 Windows 命令提示符。 What am I missing?我错过了什么?

On the method Configure in Startup.cs, remove the line在 Startup.cs 中的方法Configure上,删除该行

app.UseHttpsRedirection();

I was able to completely disable https and close port 5001 in a Blazor and thus dotnet application by removing我能够完全禁用 https 并关闭 Blazor 中的端口 5001,从而通过删除 dotnet 应用程序

app.UseHttpsRedirection();

from Program.cs and either addingProgram.cs并添加

{
  ...,

  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      }
    }
  }
}

to appsettings.json or by launching the compiled binary with --urls=http://0.0.0.0:5000 as this limits the entpoints to http only.appsettings.json或通过使用--urls=http://0.0.0.0:5000启动已编译的二进制文件,因为这将实体点限制为仅 http。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM