Posted 11/15/2024

Secure ASP.NET Server Headers

Remove server headers from response

Its always better to show headers which hold information about server, framework or language to hide the information from attacker.

builder.WebHost.ConfigureKestrel(host => { host.AddServerHeader = false;  });

Use HSTS

Always use Strict Transport Security Protocol and HTTPS Redirection in production apps:

var builder = WebApplication.CreateBuilder(args);
...
var app = builder.Build();
...
app.UseHsts();
app.UseHttpsRedirection();

Enforce HTTPS

Security headers