You can create your own piece of middleware and enter it directly into the pipeline:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use(async (context, next) =>
{
string[] headersToRemove = { "Server" };
foreach (var header in headersToRemove)
{
if (context.Response.Headers.ContainsKey(header))
{
context.Response.Headers.Remove(header);
}
}
await next();
});
}
}
or custom middleware:
using Microsoft.Owin;
using System.Threading.Tasks;
public class SniffMiddleware : OwinMiddleware
{
public SniffMiddleware(OwinMiddleware next): base(next)
{
}
public async override Task Invoke(IOwinContext context)
{
string[] headersToRemove = { "Server" };
foreach (var header in headersToRemove)
{
if (context.Response.Headers.ContainsKey(header))
{
context.Response.Headers.Remove(header);
}
}
await Next.Invoke(context);
}
}
which you can enter into the pipeline this way:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use<SniffMiddleware>();
}
}
Microsoft.Owin.Host.SystemWeb
:
Install-Package Microsoft.Owin.Host.SystemWeb
" IIS".