Reputation: 3519
I am struggling to get an ASP.NET Core 2.2 application to listen for http requests.
When I start the application dotnet run --urls http://0.0.0.0:5000
the command returns Now listening on: https://[::]:5001
And when trying to access the url: http://localhost:5000
I get an error message in the browser stating ERR_CONNECTION_REFUSED
.
Https connections do work on port 5001, but Http on port 5000 fail.
My launcSettings.json
looks like this:
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000;https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Please help by suggesting how to enable http.
I have disabled the HttpsRedirection in the Starup.cs
, but this also has no effect:
app.UseStatusCodePages();
//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
Upvotes: 4
Views: 9113
Reputation: 3519
To fix this scenario, ensure that the Program
class configures the WebHost correctly.
In the example below, two URL strings .UseUrls("https://*:5001;http://*:5000")
are provided to configure the WebHost
, ensuring the service accepts both https and http on the tcp ports 5001 and 5000.
e.g.
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("https://*:5001;http://*:5000")
.UseStartup<Startup>();
}
Upvotes: 6