This blog post discusses a significant breaking change introduced in Microsoft .NET 8 that affects ASP.NET Core applications.
Previously, in .NET 7 and earlier versions, the default port for running an ASP.NET Core web application was **80**. However, in **.NET 8, the default port has been changed to 8080**. This implies that running your existing .NET Core application (without modifications) in a container or locally on .NET 8 will result in connection issues, as it will not be accessible on port 80.
Here are two ways to address this breaking change:
If you are running your application in a container (e.g., Docker), update the port mapping in the command to expose port 8080 externally:
docker run -it --rm -p 80:8080 <your-image-name>
Set the following environment variables within your container or locally:
If you have specific reasons to use port 80, you can explicitly set the ASP.NET Core port within your application:
C# var builder = WebApplication.CreateBuilder(args); // Configure the port explicitly builder.WebHost.UseUrls("http://*:80"); // Rest of your application configuration var app = builder.Build(); // ...
Important Note: Using port 80 often requires root privileges on your system, which can pose a security risk. It is generally recommended to use a different port like 8080 and configure it accordingly.
Remember to adapt these approaches based on your specific deployment environment and container configurations. Please refer to the official documentation for further details: https://stackoverflow.com/questions/38755516/how-to-change-the-port-number-for-asp-net-core-app