HSTS (HTTP Strict Transport Security) is a security mechanism that instructs browsers to always use HTTPS when communicating with your server. ASP.NET Core includes `app.UseHsts()` middleware by default, which sends the `Strict-Transport-Security` header. The post explains what HSTS does, its key options (max-age, includeSubdomains, preload), and how to configure `HstsOptions` in ASP.NET Core. It recommends a gradual rollout strategy: start with a 5-minute max-age, test thoroughly, then increase to weeks and eventually 2 years before enabling preload. The preload flag gets your domain added to browser-hardcoded HSTS lists, preventing any HTTP communication even on the first request. HSTS should generally be enabled in production but avoided in development environments without valid certificates.

5m read timeFrom khalidabuhakmeh.com
Post cover image
Table of contents
What is HSTS?HSTS in ASP.NET CoreShould I turn on HSTS?Conclusion