Notification texts go here Contact Us Buy Now!

Steps for migrating a .NET Core Web API to .NET 8 : Part-2

Console Bee

Breaking Change in Microsoft .NET 8: Default Web Server Port

This blog post discusses a significant breaking change introduced in Microsoft .NET 8 that affects ASP.NET Core applications.

Default Web Server Port Change

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.

Addressing the Breaking Change

Here are two ways to address this breaking change:

1. Update Your Configuration

Option 1a: Modify the container command

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>
Option 1b: Adjust ASP.NET Core environment variables

Set the following environment variables within your container or locally:

  • ASPNETCORE_HTTP_PORTS: Set this to your desired port, for example, "80".
  • ASPNETCORE_HTTPS_PORTS: If you're using HTTPS, set this to your desired HTTPS port (e.g., "443").

2. Continue Using Port 80 (Use with Caution)

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

إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
NextGen Digital Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...