IIS 忽略 system.webServer staticContent 部分

发布于 2024-09-14 02:45:19 字数 3574 浏览 6 评论 0原文

UDPATE

一时兴起,我决定将 4 个字体文件上传到字体转换器。我将字体从 ttf 转换为 ttf,然后尝试一下。一切正常:Content-Type 设置正确,X-Powered-By 标头已删除。
诡异的。


我正在尝试更改 IIS7 上 web.config 中 .ttf 文件的 mime 类型(内容类型标头)。

这是 中的 staticContent 部分:

<staticContent>
    <remove fileExtension=".ttf" />
    <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
</staticContent>

即使使用上述配置,所有 .ttf 文件也会通过 application/octetstream 发送。

我还有一个包含以下内容的 customHeader 部分:

<remove name="X-Powered-By" />

它成功删除了 css、png、jpg、gif、ico、.aspx、.htm、.html、shtml 和 的 X-Powered-By 标头js 文件。但是,它不适用于 .ttf。

有人知道我做错了什么吗?


我的整个 web.config 以防万一:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
    </compilers>
  </system.codedom>
  <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
        <add name="X-UA-Compatible" value="chrome=1;IE=edge" />
      </customHeaders>
    </httpProtocol>
    <modules>
      <remove name="Session" />
      <remove name="WindowsAuthentication" />
      <remove name="FormsAuthentication" />
      <remove name="PassportAuthentication" />
      <remove name="RoleManager" />
      <remove name="UrlAuthorization" />
      <remove name="FileAuthorization" />
      <remove name="AnonymousIdentification" />
      <remove name="Profile" />
    </modules>
    <staticContent>
        <remove fileExtension=".ttf" />
        <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
    </staticContent>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

UDPATE

On a whim, I decided to upload the 4 fonts files to an font converter. I converted the fontsfrom ttf to ttf and then tried it. Everything works fine: the Content-Type is set correctly and the X-Powered-By header is removed.
Weird.


I am trying to change the mime type (Content Type header) of a .ttf file in web.config on IIS7.

Here is the staticContent section inside <system.webServer />:

<staticContent>
    <remove fileExtension=".ttf" />
    <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
</staticContent>

Even with the above configuration all .ttf files are sent with application/octetstream.

I also have a customHeader section with the following:

<remove name="X-Powered-By" />

which successfully removes the X-Powered-By header for css, png, jpg, gif, ico, .aspx, .htm, .html, shtml, and js files. It does NOT, however, work for .ttf.

Anyone know what I'm doing wrong?


My entire web.config just in case:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
    </compilers>
  </system.codedom>
  <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
        <add name="X-UA-Compatible" value="chrome=1;IE=edge" />
      </customHeaders>
    </httpProtocol>
    <modules>
      <remove name="Session" />
      <remove name="WindowsAuthentication" />
      <remove name="FormsAuthentication" />
      <remove name="PassportAuthentication" />
      <remove name="RoleManager" />
      <remove name="UrlAuthorization" />
      <remove name="FileAuthorization" />
      <remove name="AnonymousIdentification" />
      <remove name="Profile" />
    </modules>
    <staticContent>
        <remove fileExtension=".ttf" />
        <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
    </staticContent>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2024-09-21 02:45:19

修复方法是将 runAllManagedModulesForAllRequests 设置为 true

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <!-- stuff -->
    </modules>
</system.webServer>

The fix was to set runAllManagedModulesForAllRequests to true.

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <!-- stuff -->
    </modules>
</system.webServer>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文