如何在标头中添加MIME类型

How to add MIME type in headers

提问人:mrd 提问时间:11/9/2023 更新时间:11/9/2023 访问量:32

问:

我的 C# Web 应用程序工作正常。

但出于安全原因,我需要在 web.config 文件中使用“nosniff”自定义标头。

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

然后它会破坏应用程序,并且不显示任何内容。我在网络浏览器中收到以下消息:

Refused to execute script from 'https://localhost:003/extnet-ini-js/ext.axd?' because its MIME type ('application/json') is not executable and strict MIME type checking is enabled.

我正在使用基于 extnet 服务器的库。

这是一个基于服务器的 asp.net 库,我不知道如何在标头中添加MIME类型?有什么解决办法吗?

JavaScript asp.net

评论


答:

0赞 AK94 11/9/2023 #1

根据:允许后端应用 (web.config) 中所需的所有 MIME 类型。

<system.webServer>
    <staticContent>
        <remove fileExtension=".7z" />
        <mimeMap fileExtension=".7z" mimeType="application/x-7z-compressed" />
    </staticContent>
</system.webServer>

过去,允许您需要的所有类型也帮助了我。希望它对你也有帮助。

在这里,您可以找到可以使用的常用 MIME 类型的列表:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types