4

Question

How do you remove "Server:Kestrel" from the response header in a .Net Core 3 application?

enter image description here

In earlier versions you could do something like the below which is mentioned in this Stack Overflow answer.

Net Core 1

 var host = new WebHostBuilder()
    .UseKestrel(c => c.AddServerHeader = false)
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseIISIntegration()
    .UseStartup<Startup>()
    .Build();

Net Core 2

WebHost.CreateDefaultBuilder(args)
           .UseKestrel(c => c.AddServerHeader = false)
           .UseStartup<Startup>()
           .Build();

Net Core 3 (UseKestrel() is not found, and does not work, so the below is not possible.)

 public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseKestrel(c => c.AddServerHeader = false)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
Dan Cundy
  • 2,649
  • 2
  • 38
  • 65

1 Answers1

8

You should still be able to set Kestrel configuration, things have just moved a bit

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                    .ConfigureKestrel(options => options.AddServerHeader = false)
                    .UseStartup<Startup>();
            });
Krumelur
  • 31,081
  • 7
  • 77
  • 119