I have an asp.net mvc project on a https url.
I have removed X-Power-By header from IIS.
I have these lines in my web.config:
<customHeaders>
<remove name="X-AspNet-Version" />
<remove name="X-AspNetMvc-Version" />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
I have written the following class:
public class RemoveServerHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}
public void Dispose() { }
void OnPreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
}
and I have added this line in my web.config for the above class:
<modules>
<add name="RemoveServerHeaderModule" type="IZBSC.UI.Components.RemoveServerHeaderModule" />
</modules>
Even I have added the following lines to my Global.asax file:
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
And I have added the following code line to my Application_Start() method in the Global.asax:
MvcHandler.DisableMvcResponseHeader = true;
Now the server headers are removed from my pages...
But yet...
The Server header and X-Power-By header is shown for some css and jquery and picture files.
Really what should I do to remove Server and X-Power-By header from all my requests including page,style,script and image files?