asp.net - IIS 忽略 system.webServer staticContent 部分

标签 asp.net iis-7 web-config mime-types

UDPATE

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

<小时/>

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

这是 <system.webServer /> 内的 staticContent 部分:

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

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

我还有一个自定义标题部分,其中包含以下内容:

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

成功删除 X-Powered-By css、png、jpg、gif、ico、.aspx、.htm、.html、shtml 和 js 文件的 header 。但是,它不适用于 .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>

最佳答案

修复方法是将 runAllManagedModulesForAllRequests 设置为 true

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

关于asp.net - IIS 忽略 system.webServer staticContent 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3461329/

相关文章:

asp.net - 如何使用 Team Build 部署 ASP.NET Web 应用程序?

iis-7 - 如何在 IIS 经典模式池下托管 ASP.NET 5 (vNext) MVC 6 项目

asp.net - 使用 WindowsAuthenticationModule 时在哪里添加 WWW-Authenticate header

asp.net - 在 Asp.Net 中使用 SqLite

.net - 如何使用 XSLT 删除属性值与给定值不同的节点?

asp.net - 无法呈现网址。无法从 url 获取图像。导航超时

asp.net - 我可以在母版页中使用 UpdatePanel 来包装嵌套页面吗?

asp.net - 如何在 C# 2.0 中加密 Web.config 中的用户名和密码

c# - 从 ASP.NET App Pool Identity 运行命令

asp.net - 以编程方式注册自定义 ASP.NET ExpressionBuilder