Developing locally with ASP.NET under HTTPS, SSL, and Self-Signed Certs
SLL Certs Ploblem
เมื่อสั่งรันโปรเจคด้วยคำสั่ง dotnet run โปรแกรมจะทำการจำลองเว็บเซิร์ฟเวอร์ขึ้นมาโดยให้เราสามารถเข้าถึงได้ทาง HTTP ผ่านพอร์ต 5000 และ HTTPS ผ่านพอร์ต 5001
[07:47:59 INF] The output logging directory is: E:\Projects\FilesLocalStorage\Logs
[07:47:59 INF] Getting the AtlasX Web Service running...
[07:48:00 INF] Telerik Reporting Temp Data: C:\Users\00xxxx\Telerik Reporting Temp
[07:48:01 INF] User profile is available. Using 'C:\Users\00xxxx\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[07:48:01 INF] Now listening on: http://localhost:5000
[07:48:01 INF] Now listening on: https://localhost:5001
[07:48:01 INF] Application started. Press Ctrl+C to shut down.
[07:48:01 INF] Hosting environment: Development
[07:48:01 INF] Content root path: E:\Projects\MyDotNetProjectอย่างไรก็ตามถ้าเราเข้าถึง https://localhost:5001 เราจะเจอ Error ดังรูป

เป็นเพราะเว็บบราวเซอร์มองว่าใบรับรอง SSL จากเครื่องของเราเองไม่น่าเชื่อถือ
Trust SSL Certs
มีเครื่องมือใน .NET ที่ใช้สำหรับจัดการ Certificate บนเครื่อง Developer เรียกว่า dev-certs
dotnet dev-certs https --helpUsage: dotnet dev-certs https [options]
Options:
-ep|--export-path Full path to the exported certificate
-p|--password Password to use when exporting the certificate with the private key into a pfx file or to encrypt the Pem exported key
-np|--no-password Explicitly request that you don't use a password for the key when exporting a certificate to a PEM format
-c|--check Check for the existence of the certificate but do not perform any action
--clean Cleans all HTTPS development certificates from the machine.
-i|--import Imports the provided HTTPS development certificate into the machine. All other HTTPS developer certificates will be cleared out
--format Export the certificate in the given format. Valid values are Pfx and Pem. Pfx is the default.
-t|--trust Trust the certificate on the current platform. When combined with the --check option, validates that the certificate is trusted.
-v|--verbose Display more debug information.
-q|--quiet Display warnings and errors only.
-h|--help Show help informationเพื่อทำการ Trust Certificate บนเครื่อง Developer ให้เราใช้คำสั่ง
dotnet dev-certs https --trustจากนั้น จะมีป๊อปอัปถามว่าต้องการเชื่อถือใบรับรอง localhost นี้หรือไม่ ให้เราตอบ Yes เพื่อยอมรับและเชื่อถือ Certificate

ปิดเว็บบราวเซอร์แล้วปิดใหม่อีกครั้งแล้วเข้าไปที่ https://localhost:5001 เราจะเห็นคำว่า Secure บน Address Bar
