Removing ASP.NET Server Headers in ASP.NET Core and IIS



Last updated: October 28th, 2026

Updated October 2026: the code is now inline, with tested settings for Kestrel, IIS 10 and classic ASP.NET, plus a quick way to check your headers.

Quick Answer

  • Kestrel (Server: Kestrel): builder.WebHost.ConfigureKestrel(o => o.AddServerHeader = false);
  • IIS 10+ (Server: Microsoft-IIS/10.0): <requestFiltering removeServerHeader="true" /> in web.config.
  • X-Powered-By: ASP.NET (added by IIS): <remove name="X-Powered-By" /> under customHeaders.
  • X-AspNet-Version / X-AspNetMvc-Version (.NET Framework only): enableVersionHeader="false" and MvcHandler.DisableMvcResponseHeader = true.

Web applications and servers send various headers in their HTTP responses. Some describe the content or control caching; others simply announce the software running the site. In the ASP.NET world, X-Powered-By and Server: Kestrel or Server: Microsoft-IIS/10.0 are the common ones. Here is why and how to remove them.

Why Remove These Headers?

Security through obscurity (as one layer)

Hiding headers isn't a defense on its own, but combined with patching and other controls it is a cheap extra layer.

  • Information leakage: headers like X-Powered-By and Server tell anyone exactly which platform and version you run, which makes automated scanners' job easier.
  • Less to target: without them, an attacker has to work harder to fingerprint your stack, and opportunistic attacks that key on version strings skip you.
  • Security scanners and audits (PCI scans, penetration tests, tools like Mozilla Observatory) routinely flag these headers, so removing them saves a finding.

Professionalism and consistency

  • A polished service doesn't advertise its tooling, and responses look the same across services built on different stacks.
  • The bandwidth saved is tiny per request, but it is free.

ASP.NET Core and Kestrel

Kestrel adds Server: Kestrel by default. Turn it off in Program.cs. The middleware below also removes X-Powered-By if something upstream added it, and sets two useful security headers while you're there:

// Program.cs: remove "Server: Kestrel" and add a few security headers.
var builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(options => options.AddServerHeader = false);

var app = builder.Build();

app.Use(async (context, next) =>
{
    context.Response.OnStarting(() =>
    {
        IHeaderDictionary headers = context.Response.Headers;
        headers.Remove("X-Powered-By");            // only if something upstream added it
        headers["X-Content-Type-Options"] = "nosniff";
        headers["Referrer-Policy"] = "strict-origin-when-cross-origin";
        return Task.CompletedTask;
    });
    await next();
});

app.MapGet("/", () => "Hello");
app.Run();

Verified on .NET 10: with this code the response has no Server header at all.

IIS 10 (and ASP.NET Core Behind IIS)

When your app is hosted in IIS, IIS itself adds Server: Microsoft-IIS/10.0 and X-Powered-By: ASP.NET. Since IIS 10 (Windows Server 2016 and later) you can remove both in web.config, without recompiling:

<?xml version="1.0" encoding="utf-8"?>
<!-- IIS 10+: remove the Server and X-Powered-By headers without recompiling -->
<configuration>
  <system.webServer>
    <security>
      <requestFiltering removeServerHeader="true" />
    </security>
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

Put it in the site's web.config (ASP.NET Core publishes one; add these sections inside system.webServer), or at the server level in IIS Manager to cover every site.

Classic ASP.NET (.NET Framework)

.NET Framework apps add two more version headers. Remove them like this:

<!-- ASP.NET (.NET Framework): also remove X-AspNet-Version and X-AspNetMvc-Version -->
<configuration>
  <system.web>
    <httpRuntime enableVersionHeader="false" />
  </system.web>
</configuration>
<!-- and in Global.asax Application_Start():  MvcHandler.DisableMvcResponseHeader = true; -->

Check Your Headers

curl -sI https://example.com/

Look for Server, X-Powered-By, X-AspNet-Version and X-AspNetMvc-Version in the output. Behind a CDN or reverse proxy (Cloudflare, nginx, a load balancer), the proxy may add its own Server header; that one has to be changed at the proxy.

Frequently Asked Questions

How do I remove the Server: Kestrel header?

Set AddServerHeader = false in the Kestrel options: builder.WebHost.ConfigureKestrel(options => options.AddServerHeader = false);

How do I remove the Server header in IIS?

On IIS 10 and later, add <security><requestFiltering removeServerHeader="true" /></security> under system.webServer in web.config. Older IIS versions need the URL Rewrite module or a custom module.

Does removing the Server header improve security?

Slightly. It hides version information from casual scanning, but keeping software patched matters far more. Treat it as one small layer, not a fix.

Related: filtering bot traffic by user agent in ASP.NET and serving an IIS site over Tor.


Comments

No Comments

CAPTCHA

Tagged: ASP.NET Core


Join my email list!



ryan
About Me

With over 15 years in tech, I've excelled as a senior software engineer, specializing in ASP.NET, C#, SQL, Azure, and front-end technologies. I've led diverse projects across various sectors, from startups to global corporations, particularly during my decade in the San Francisco Bay Area.


Sign Up Hostinger Email