IIS忽略system.webServer staticContent部分

时间:2010-08-11 17:52:42

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

UDPATE

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


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

以下是<system.webServer />中的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和js文件的X-Powered-By标头。但是,它并不适用于.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>

1 个答案:

答案 0 :(得分:2)

修复方法是将runAllManagedModulesForAllRequests设置为true

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