以下更改允许您在编写自定义HttpModule时删除Azure without中的这些HTTP响应头.
网络上的大多数信息都是过时的,并且涉及到UrlScan(它后来被集成到IIS7中,但删除了RemoveServerHeader=1
选项).下面是我找到的最简洁的解决方案(这要归功于this blog、this answer和this blog的总和).
要删除Server,请转到"全局".尽快找到/创建Application_PreSendRequestHeaders
事件并添加以下内容(感谢BK和this blog,这在卡西尼/本地开发人员上也不会失败):
2014年4月编辑:可以将PreSendRequestHeaders和PreSendRequestContext事件与本机IIS模块一起使用,但不要将它们与实现IHttpModule的托管模块一起使用.设置这些属性可能会导致asynchronous requests出现问题.正确的版本是使用BeginRequest事件.
protected void Application_BeginRequest(object sender, EventArgs e)
{
var application = sender as HttpApplication;
if (application != null && application.Context != null)
{
application.Context.Response.Headers.Remove("Server");
}
}
要删除X-AspNet-Version,请在web中.配置查找/创建<system.web>
并添加:
<system.web>
<httpRuntime enableVersionHeader="false" />
...
要删除X-AspNetMvc-Version,请转到Global.asax,查找/创建Application_Start
事件并添加一行,如下所示:
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
}
要删除X-Powered-By,请在web中.配置查找/创建<system.webServer>
并添加:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
...