X-Content-Type-Options is a security response header. Setting it to nosniff helps prevent browsers from MIME-type sniffing and adds protection against cross-site scripting attacks. section 31.1.3
Add the header as cross-cutting ASP.NET Core middleware:
- Register a response-starting callback with context.Response.OnStarting. section 31.1.3
- Call next() so the remaining pipeline generates the response. section 31.1.3
Apply it to every response
app.Use(async (HttpContext context, Func<Task> next) => { context.Response.OnStarting(() => { context.Response.Headers["X-Content-Type-Options"] = "nosniff"; return Task.CompletedTask; }); await next(); });

