This depends on where you configure your production Url. There are roughly half a dozen places, where you can store them out of the box.
LazZiya has given you an approach that works just fine locally, but hits some limitations, once you exceed the scenario, where there is only dev and prod.
If you configure them in your appsettings.json and as an environment variable, the environment variable take have precedence. If your app is going to be containerized, chances are, that most of these values will be set using einvironment variables.
To read those use Environment.GetEnvironmentVariable("ASPNETCORE_URLS"), which would give you the internal urls Kestrel is listening on. public addresses, will probably have a different key - but you get the idea.
You can read up on this here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0