Search code examples
asp.net-coreasp.net-core-mvchttp2

How to enable http/2 in Asp.net core 2.2 kestrel (self hosted) on server 2016


I have just updated my project from asp.net core 2.1 to 2.2 (main reason was Brotli- and http/2 support).
I was able to rebuild, deploy and start the app (self hosted console app).
The app run’s on a Windows 2016 server and has https enabled (over a public certificate).
The server supports TLS 1.2 (checked over the internet with a tool).
Unfortunately http/2 don’t work, whereby Brotli compression seems to work.
My client also does support http/2 - if I have a look to my website with GC, I can see, that some of my referenced files are server over http/2, but not my content.

According to the found Information’s on the web:

  • My configuration should meet the prerequisites for http/2
  • Asp.net core 2.2 should use http/2 automatically (without any change in code or settings) per default and do a fallback to http/1.1 automatically, if a client don’t support http/2

What do I miss here...?


Solution

  • Just found the solution myself...
    I use an appsettings.json to configure the kestrel on the server:

    {
      "Logging": {
        "LogLevel": {
          "Default": "Warning"
        }
      },
      "AllowedHosts": "*"
    ,
        "Kestrel": {
            "EndPoints": {
                "Http": {
                    "Url": "http://localhost:5000"
                },
                "HttpsInlineCertFile": {
                    "Url": "https://nnn.nnn.n.n:nnnnn",
                    "Protocols": "Http1AndHttp2",  
                    "Certificate": {
                        "Path": "./certificate.pfx",
                        "Password": "Password",
                        "AllowInvalid": "true"
                    }
                }
            }
        }
    }
    

    I had to add the entry: "Protocols": "Http1AndHttp2",

    Now, it seems to work (GC shows "h2" to the protocol now).
    But the result is not as expected (seems to be a bit slower now..).
    However, this was the solution for my initial posting.
    Hope this helps someone...