There are 3 main ways:
1️⃣ launchSettings.json (Local Development Only)
- 
Located in:
Properties/launchSettings.json 
Example:
π This means:
- 
ProductService will listen on
http://localhost:5002andhttps://localhost:7002. - 
Useful for local debugging.
 
2️⃣ appsettings.json or appsettings.{Environment}.json
- 
You can configure Kestrel endpoints directly.
 
Example:
π This works in development, staging, and production.
π More flexible, especially when deploying in Docker/Kubernetes.
3️⃣ Hardcode in Program.cs (Not Recommended for Production)
π Quick way to bind to specific ports, but harder to manage in large deployments.
⚙️ Best Practices
- 
Local Development → use
launchSettings.json. - 
Production (IIS, Azure, Docker, Kubernetes) →
- 
Use
appsettings.json(Kestrel:Endpoints). - 
Or environment variables →
DOTNET_URLS=http://+:5002. 
 - 
 - 
Dockerized Microservices → expose ports in
Dockerfile/docker-compose.yml. Example: 
✅ Summary
- 
launchSettings.json → local dev only.
 - 
appsettings.json (Kestrel) → preferred for production.
 - 
Program.cs → UseUrls() → quick overrides.
 - 
Environment Variables / Docker → best in containerized/cloud setups.