Fixed the issue by implementing the code on this page and then changing the line below: https://docs.kentico.com/k10/securing-websites/deploying-websites-to-a-secure-environment/configuring-ssl/ssl-accelerator-support
Change
string forwardedSSL = headers.Get("HTTP_X-Forwarded-Proto");
To
string forwardedSSL = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X-Forwarded-Proto"];