Peter
Peter

Reputation: 448

Disable https dotnet core 3.0 webapi

For dotnet core 2.x I was able to modify the program.cs file to specify ports:

        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. The default program.cs file for dotnet core webapi has this:

        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. It looks like this option removes https from the launchSettings.json file. I am not using Visual Studio or any IDE, only the Windows Command Prompt. What am I missing?

Upvotes: 1

Views: 2401

Answers (2)

Mr.Yellow
Mr.Yellow

Reputation: 732

I was able to completely disable https and close port 5001 in a Blazor and thus dotnet application by removing

app.UseHttpsRedirection();

from Program.cs and either adding

{
  ...,

  "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 endpoints to http only.

Upvotes: 2

Magnetron
Magnetron

Reputation: 8543

On the method Configure in Startup.cs, remove the line

app.UseHttpsRedirection();

Upvotes: 1

Related Questions