Ghooti Farangi
Ghooti Farangi

Reputation: 20176

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

}

Upvotes: 4

Views: 2831

Answers (1)

Kev
Kev

Reputation: 119856

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.

Upvotes: 6

Related Questions