gpt4 book ai didi

security - Azure Web 角色过多 header

转载 作者:行者123 更新时间:2023-12-03 04:45:11 26 4
gpt4 key购买 nike

我有一个在 Azure Web 角色中运行的网站。我针对 asafaweb.com 测试了该网站,并收到“标题过多”警告。

asafaweb.com screenshot

基本上,Azure 将 IIS 版本和 .net 版本作为 header 的一部分发送出去。

有大量关于如何在 IIS 中关闭这些 header 的信息,但如何在 Azure 中关闭它们?

最佳答案

这是我在大多数项目中用来隐藏这些 header 的方法:

Global.asax.cs(仅适用于 MVC 项目)

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

自定义 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>

关于security - Azure Web 角色过多 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11751644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com