无法在 ASP.NET/IIS7 经典模式下设置 HTTP 响应标头
有一个 HttpModule 可以更改响应标头中的服务器字段。但它不适用于 ASP.NET/IIS7 经典模式。删除或更改响应标头中的服务器字段的解决方案是什么?
public class CloakHttpHeaderModule : IHttpModule
{
public void Init(HttpApplication app)
{
app.PreSendRequestHeaders += new EventHandler(context_PreSendRequestHeaders);
}
public void Dispose()
{
}
private void context_PreSendRequestHeaders(object sender, EventArgs e)
{
var context = ((HttpApplication)sender).Context;
context.Response.Headers.Set("Server", "Apache 2.0");
//HttpContext.Current.Response.Headers.Set("Server", "WSGIServer/0.1 Python/2.6.1");
}
}
There is a HttpModule that change Server field in Response Headers. But it does not work in ASP.NET/IIS7 classic mode. what is the solution for remove or change Server field in reponse header?
public class CloakHttpHeaderModule : IHttpModule
{
public void Init(HttpApplication app)
{
app.PreSendRequestHeaders += new EventHandler(context_PreSendRequestHeaders);
}
public void Dispose()
{
}
private void context_PreSendRequestHeaders(object sender, EventArgs e)
{
var context = ((HttpApplication)sender).Context;
context.Response.Headers.Set("Server", "Apache 2.0");
//HttpContext.Current.Response.Headers.Set("Server", "WSGIServer/0.1 Python/2.6.1");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您至少运行 IIS7、集成管道模式和 .NET 3.0,否则无法执行此操作。该文档指出:
You can't do this unless you're running at least IIS7, Integrated Pipeline Mode and .NET 3.0. The documentation states this: