Can't access .NET Core app from public IP

Troubleshooting an ASP.NET Core 7.0 MVC Web Application

I have an Amazon EC2 Windows instance running an ASP.NET Core 7.0 MVC web application (Hello World). I installed .NET 7.0 before deploying, building and running the HelloWorld app using dotnet run.

The following code is used to configure the web application:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

The launchSettings.json file is configured as follows:

"http": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "applicationUrl": "http://localhost:5223",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},
"https": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "applicationUrl": "https://localhost:7174;http://localhost:5223",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},

In order to access the application, the following ports are open with the Security Group:

  • HTTPS 443
  • HTTP 80
  • WebApp HTTP 5223
  • WebApp HTTPS 7174
  • RDP 3389

The following screenshot shows the Inbound Rules configured in Windows Defender Firewall with Advanced Security:

enter image description here

The problem is that I’m unable to access the Hello World app using the Public IPv4 address or Public IPv4 DNS provided by the EC2 instance.

The issue might be related to the Windows Defender Firewall settings. You need to allow inbound traffic on port 5223 and 7174 for the web application.

To resolve the issue, follow these steps:

  1. Open the Windows Defender Firewall with Advanced Security.
  2. Click on Inbound Rules in the left-hand pane.
  3. Click on New Rule in the right-hand pane.
  4. Select Port and click Next.
  5. Select TCP and enter port number 5223 in the Specific local ports field. Click Next.
  6. Select Allow the connection and click Next.
  7. Make sure all the checkboxes are selected for the Domain, Private, and Public profiles. Click Next.
  8. Enter a name for the rule (e.g., WebApp HTTP) and click Finish.
  9. Repeat steps 3-8 to create a new rule for port 7174 (WebApp HTTPS).

After creating these rules, you should be able to access the Hello World app using the Public IPv4 address or Public IPv4 DNS provided by the EC2 instance.