Kestrel:在不相容的 Windows 版本上,TLS 上的 HTTP/2 已停用

若要在 Windows 上透過 Transport Layer Security (TLS) 啟用 HTTP/2,必須符合兩個需求:

  • Application-Layer Protocol Negotiation (ALPN) 支援 (從 Windows 8.1 和 Windows Server 2012 R2 開始提供)。
  • 一組與 HTTP/2 相容的加密 (從 Windows 10 和 Windows Server 2016 開始提供)。

因此,當設定 HTTP/2 over TLS 時,Kestrel 的行為已變更為:

  • 會在 ListenOptions.HttpProtocols 設為 Http1AndHttp2 時,降級為 Http1 並在 Information 層級記錄訊息。 Http1AndHttp2ListenOptions.HttpProtocols 的預設值。
  • 會在 ListenOptions.HttpProtocols 設為 Http2 時擲出 NotSupportedException

如需討論,請參閱問題 dotnet/aspnetcore#23068

導入的版本

ASP.NET Core 5.0

舊的行為

下表概述設定 HTTP/2 over TLS 時的行為。

通訊協定 Windows 7、
Windows Server 2008 R2
或更早版本
Windows 8、
Windows Server 2012
Windows 8.1、
Windows Server 2012 R2
Windows 10、
Windows Server 2016、
或更新
Http2 擲出 NotSupportedException TLS 交握期間發生錯誤 TLS 交握期間發生錯誤 * 沒有錯誤
Http1AndHttp2 降級為 Http1 降級為 Http1 TLS 交握期間發生錯誤 * 沒有錯誤

* 設定相容的加密套件以啟用這些案例。

新的行為

下表概述設定 HTTP/2 over TLS 時的行為。

通訊協定 Windows 7、
Windows Server 2008 R2
或更早版本
Windows 8、
Windows Server 2012
Windows 8.1、
Windows Server 2012 R2
Windows 10、
Windows Server 2016、
或更新
Http2 擲出 NotSupportedException 擲出 NotSupportedException 擲出 NotSupportedException ** 沒有錯誤
Http1AndHttp2 降級為 Http1 降級為 Http1 降級為 Http1 ** 沒有錯誤

** 設定相容的加密套件,並將應用程式內容參數 Microsoft.AspNetCore.Server.Kestrel.EnableWindows81Http2 設為 true 以啟用這些案例。

變更原因

這項變更可確保儘早、盡可能清楚地顯示在舊版 Windows 上 HTTP/2 over TLS 的相容性錯誤。

請確定 HTTP/2 over TLS 已在不相容的 Windows 版本上停用。 Windows 8.1 和 Windows Server 2012 R2 不相容,因為它們預設缺少必要的加密。 不過,可以更新電腦組態設定來使用 HTTP/2 相容的加密。 如需詳細資訊,請參閱 Windows 8.1 中的 TLS 加密套件。 設定之後,必須透過設定應用程式內容參數 Microsoft.AspNetCore.Server.Kestrel.EnableWindows81Http2,來啟用在 Kestrel 上的 HTTP/2 over TLS。 例如:

AppContext.SetSwitch("Microsoft.AspNetCore.Server.Kestrel.EnableWindows81Http2", true);

基本支援沒有變更。 例如,HTTP/2 over TLS 從未在 Windows 8 或 Windows Server 2012 上運作。 這項變更修改了這些不受支援案例中的錯誤呈現方式。

受影響的 API