我有一个不使用owin中间件的应用程序,它具有以下Global.asax
:
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
//...
}
protected void Application_PreSendRequestHeaders()
{
Response.Headers.Remove("Server");
}
}
这将在应用程序每次发送响应时删除
Server
头。如何对使用owin的应用程序执行相同的操作?
public class Startup
{
public void Configuration(IAppBuilder application)
{
//...
}
//What method do I need to create here?
}
最佳答案
您可以为IOwinResponse.OnSendingHeaders
事件注册回调:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use(async (context, next) =>
{
context.Response.OnSendingHeaders(state =>
{
((OwinResponse)state).Headers.Remove("Server");
}, context.Response);
await next();
});
// Configure the rest of your application...
}
}