Why can't I uninstall X-Powered-By as part of my middleware that I run? I can remove it if I put it in web.config, but not if I put it in middleware. I delete another header in the Server middleware: Kestrel, which works and tells me that my middleware is running.
I am using Visual Studio 2015, the basic ASP.NET web application (.NET Framework), 1.0.0-rc2-final
My middleware
public class ManageHttpHeadersMiddleware
{
private RequestDelegate _next;
public ManageHttpHeadersMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
context.Response.OnStarting(() =>
{
context.Response.Headers.Remove("Server");
context.Response.Headers.Remove("X-Powered-By");
return Task.CompletedTask;
});
await _next(context);
}
}
My Startup.Configure method looks like
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.ConfigurationSection(Configuration.GetSection("Serilog"))
.CreateLogger())
.AddDebug();
app.UseMiddleware<ManageHttpHeadersMiddleware>();
app.UseJwtBearerAuthentication();
app.UseMvc();
app.UseSwaggerGen();
app.UseSwaggerUi();
}
So my questions are:
- Is it because of the order in which I run the intermediate Startup.Configure?
- - , ? OnCompleted, , , "Server": "Kestrel"
- ,
Kestrel IIS Azure,
web.config?
, , , , .. ..