如何从响应中删除 IIS 自定义标头,例如 X-Powered-By: ASP.NET?

27

本文介绍了如何从响应中删除 IIS 自定义标头,例如 X-Powered-By: ASP.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

IIS 7.0 集成模式 使用 Response.ClearHeaders() 删除所有标头后,IIS 会添加一些其他标头,例如 ServerX-Powered-By 向黑客揭示了好的信息.我怎样才能停止这种行为(考虑我仍然需要添加我的自定义标题)?

In IIS 7.0 integrated mode after deleting all headers with Response.ClearHeaders() IIS would add some other headers like Server and X-Powered-By which reveals good information to hackers. How can I stop this behavior (consider I still need to add my custom headers) ?

推荐答案

您可以将其添加到您的 Web.Config:

You can add this to your Web.Config:

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

更新:如果您使用的是 MVC 框架,我还建议您删除 X-AspNetMvc-VersionX-AspNet-Version 标头.这是通过在 Global.asax 文件中设置 MvcHandler.DisableMvcResponseHeader = true<system.web><httpRuntime enableVersionHeader="false"/></system.web> 在你的 Web.config 中.

Update: if you're using the MVC framework I would also recommend removing the X-AspNetMvc-Version and X-AspNet-Version headers as well. This is accomplished by setting MvcHandler.DisableMvcResponseHeader = true in your Global.asax file and <system.web><httpRuntime enableVersionHeader="false" /></system.web> in your Web.config respectively.

这篇关于如何从响应中删除 IIS 自定义标头,例如 X-Powered-By: ASP.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

函数委托与函数
Func Delegate vs Function(函数委托与函数)...
2023-11-11 C#/.NET开发问题
6

针对委托检查 MethodInfo
Checking a MethodInfo against a delegate(针对委托检查 MethodInfo)...
2023-11-11 C#/.NET开发问题
7

如何从 lambda 表达式中获取引用实例的实例
How to get the instance of a referred instance from a lambda expression(如何从 lambda 表达式中获取引用实例的实例)...
2023-11-11 C#/.NET开发问题
4

如何为具有空目标的实例方法创建委托?
How to create a delegate to an instance method with a null target?(如何为具有空目标的实例方法创建委托?)...
2023-11-11 C#/.NET开发问题
6