Remove “Server” header from ASP.NET Core 2.1 application

前端 未结 4 1046
[愿得一人]
[愿得一人] 2021-02-07 00:23

Is it possible to remove the Server Response header in a ASP.NET Core 2.1 application (running on Server 2016 with IIS 10)?

I tried putting the followin

4条回答
  •  -上瘾入骨i
    2021-02-07 00:51

    The Kestrel Server header gets added too late in the request pipeline. Therefore removing it via the web.config or via middleware is not possible.

    You can remove the Server header by setting the AddServerHeader property to false on KestrelServerOptions, this can be done in the Program.cs.

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseKestrel(options => options.AddServerHeader = false)
                .UseStartup();
    

提交回复
热议问题