如何在所有响应标头中添加“X-Content-Type-Options:nosniff”

时间:2022-02-26 20:15:50

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中是否有一个标志或类似的东西可以做到这一点?

1 个解决方案

#1


36  

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

#1


36  

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