0

I have a website running in Azure Web Roles. I tested the site against asafaweb.com and got an "Excessive Headers" warning.

asafaweb.com screenshot

Basically Azure sends out the IIS version and the .net version as part of the header.

There is plenty of information on how to turn these headers off in IIS, but how do I turn them off in Azure?

Greg
  • 3,442
  • 3
  • 29
  • 50

3 Answers3

3

This is what I use in most projects to hide these headers:

Global.asax.cs (only applies to MVC projects)

protected void Application_Start()
{
    MvcHandler.DisableMvcResponseHeader = true;
}

Custom HttpModule

public class RemoveHeadersHttpModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.PreSendRequestHeaders += OnPreSendRequestHeaders;
    }

    private void OnPreSendRequestHeaders(object sender, EventArgs e)
    {
        HttpContext.Current.Response.Headers.Remove("Server");
        HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
    }

    public void Dispose()
    {

    }
}

web.config

  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="Server" />
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>

    <modules runAllManagedModulesForAllRequests="true">
      . . .
      <add name="RemoveHeadersHttpModule" type="MyNamespace.RemoveHeadersHttpModule"/>
    </modules>

    . . . 
  </system.webServer>
Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
2

If you want a complete solution to remove all Excessive Headers on Azure that also works with Cassini without using a custom HttpModule, see here:

Removing/Hiding/Disabling excessive HTTP response headers in Azure/IIS7 without UrlScan

Community
  • 1
  • 1
Nick Evans
  • 3,279
  • 2
  • 25
  • 21
1

Windows Azure Web Roles are essentially Windows Server 2008, with IIS enabled. So, if you wanted to tailor IIS, you could use a startup script and call appcmd to change the settings you want (or manipulate it in any other way you usually do). Your script would look something like:

%windir%\system32\inetsrv\appcmd set ...

David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • I haven't actually tried this out. i'm sure it would work but @sandrino Di Mattia's answer was much simpler – Greg Aug 20 '12 at 06:45