asp.net-mvc 如何将“X-Content-Type-Options: nosniff”添加到所有响应标头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24138507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:43:28  来源:igfitidea点击:

How can I add “X-Content-Type-Options: nosniff” to all the response headers

asp.net-mvciis

提问by AbbasFaisal

I am running an ASP.NET MVC 3 website on IIS. Is there a flag in web.config or something similar that can do this?

我在 IIS 上运行一个 ASP.NET MVC 3 网站。web.config 或类似的东西中是否有一个标志可以做到这一点?

回答by Steven V

As long as you're using IIS 7 or above, it's as simple as adding it to your web.config.

只要您使用的是 IIS 7 或更高版本,只需将其添加到您的 web.config 中即可。

<configuration>
   <system.webServer>
      <httpProtocol>
         <customHeaders>
            <add name="X-Content-Type-Options" value="nosniff" />
         </customHeaders>
      </httpProtocol>
   </system.webServer>
</configuration>

Or you can add them using the IIS Management GUI, or even command line. Take a look at http://www.iis.net/configreference/system.webserver/httpprotocol/customheaders

或者您可以使用 IIS 管理 GUI 甚至命令行添加它们。看看http://www.iis.net/configreference/system.webserver/httpprotocol/customheaders