【问题标题】:Can't set HTTP Response header in ASP.NET/IIS7 classic mode无法在 ASP.NET/IIS7 经典模式下设置 HTTP 响应标头
【发布时间】:2011-08-11 11:14:01
【问题描述】:

有一个 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");
    }

}

【问题讨论】:

    标签: asp.net iis-7 httpmodule


    【解决方案1】:

    除非您至少运行 IIS7、集成管道模式和 .NET 3.0,否则您无法执行此操作。文档说明了这一点:

    HttpResponse.Headers Property

    Headers 属性仅支持 IIS 7.0 集成 管道模式和至少 .NET Framework 3.0。当你尝试 访问 Headers 属性,这两个条件中的任何一个都不是 遇到,则抛出 PlatformNotSupportedException。

    【讨论】:

    • 太糟糕了,我有 SSRS 2012,它使用 .NET Framework 2.0 并在 IIS
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 2017-08-28
    • 1970-01-01
    • 2020-01-26
    • 2012-06-19
    相关资源
    最近更新 更多