简体   繁体   中英

Can't set HTTP Response header in ASP.NET/IIS7 classic mode

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

}

You can't do this unless you're running at least IIS7, Integrated Pipeline Mode and .NET 3.0. The documentation states this:

HttpResponse.Headers Property

The Headers property is only supported with the IIS 7.0 integrated pipeline mode and at least the .NET Framework 3.0. When you try to access the Headers property and either of these two conditions is not met, a PlatformNotSupportedException is thrown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM