インドカレーファンクラブ

パソコン、カメラ

【.NET5】【Mac】俺達はあと何回Unable to configure HTTPS endpoint.に苦しまされればいい 〜WebAPをTerminalじゃなくてVSから起動したらうまくいくかもよ〜

Macdotnet開発をしていたら何度もこの問題に苦しまされる(と個人的には思う)

web_1  | 2021-03-05 13:04:02.9459|FATAL|Microsoft.AspNetCore.Server.Kestrel|Unable to start Kestrel.
web_1  | Unhandled exception. 2021-03-05 13:04:02.9582|ERROR|web.Program|Stopped program because of exception
web_1  | System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
web_1  | To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
web_1  | For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
web_1  |    at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
web_1  |    at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
web_1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
web_1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context)
web_1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
web_1  |    at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
web_1  |    at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
web_1  |    at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
web_1  |    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
web_1  |    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
web_1  |    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
web_1  |    at web.Program.Main(String[] args) in /src/web/Program.cs:line 17

基本的にはここが参考になる

https://programming-jissen.com/how-to-deal-with-unable-to-configure-https-endpoint/

というより、つまりMSDoc

docs.microsoft.com

で、ここに書いてある方法で解決しない時がある
なんでかわからんけど

解決しなかったときのパターンを具体的に書くと

  1. VisualStudioで作成したWebアプリケーション+Docker連携に対してTerminalからdocker-compose upをして上記のエラーが出て...
  2. キーチェーンからlocalhostを削除して...(ログインとシステム両方)
  3. dotnet dev-certs https --clean, dotnet dev-certs https --trustをして...
  4. また1と同じようにupしてエラーが出て...

そんな時には表題の通り、TerminalではなくてVisualStudioのdocker-composeプロジェクト(docker-compose.dcproj)をスタートアッププロジェクトにして起動したらうまくいった
→ 起動後にキーチェーンの認証ウィンドウが開くのでPWを入力し「常に許可」を選択

なんでかわからん(2回目)けどうまくいったので困ったら試してみてください