'.NET5 self-contained webAPI with HTTPS

What would be the best way to allow only HTTPS connections with a self hosted .NET5 webApi? And how do I go about configuring an SSL Certificate (either real or self-signed)?

I've only used IIS deployments so I'm struggling to understand how to make a webserver I don't control use a specific certificate..



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source