appharborサポートから返信を受け取った後、静的ファイル用のカスタムRequireHttpsAttributeに似たコードも実装することを提案しました。 HttpRequestModuleというクラスを作成し、すべてのリクエスト(runAllManagedModulesForAllRequestsがtrueに設定されている)で実行するように設定しました。HTTP URLへの直接リクエストを強制的にHTTPSにリダイレクトできました。
class HttpRequestModule : IHttpModule
{
public void Init(HttpApplication app)
{
app.BeginRequest += new EventHandler(CheckHttpRequest);
}
private void CheckHttpRequest(object sender, EventArgs a)
{
if (app.Context.Request.IsSecureConnection) return;
if (app.Contact.Request.IsLocal) return;
if (string.Equals(app.Context.Request.Headers["X-Forwarded-Proto"],
"https",
StringComparison.InvariantCultureIgnoreCase))
{
return;
}
var secureUrl = "https://" + app.Context.Request["HTTP_HOST"] + HttpContext.Current.Request.RawUrl;
app.Context.Response.Redirect(secureUrl);
}
}