How To Deploy Angular And .NET Core Web API On IIS?
The CORS error explains everything you need to know. You need to configure CORS also for the public IP and DNS if you use also access by DNS name. It has to be configured for the exact same URL you use to access the Angular application.
app.UseCors(options =>
options.WithOrigins(
"http://localhost:4200/",
"http://{public IP}:{public port}/",
"http://{public DNS name}:{public port}/"
).AllowAnyMethod().AllowAnyHeader());
You need only CORS settings for the Angular client addresses because the Angular application needs to obtain permission to make CORS requests to your Web API. It calls from the public address so the localhost
configuration does not help this just helps when you access it locally with localhost.
Here are links to the Angular documentation about CORS and the Microsoft documentation how to enable CORS where it is described in detail.