zpjx 发表于 2017-12-28 17:35:58

[转发]如何在ASP.NET的web.config配置文件中添加MIME类型

  常常有一些特殊的MIME类型是IIS中没有的,一般来说要我们自己手动添加。如果网站经常更换服务器或者网站代码是提供给多个用户使用,那么会造成网站中用到的特殊的MIME类型要经常性的在IIS上配置。这里考虑到一个网站配置通用性问题,所以我们可以将MIME类型添加到ASP.NET网站的配置文件中,这样用户就不用一直配置IIS了。
  一般来说我们是将MIME的这部份信息配置在system.webServer节点的staticContent节点中,配置的时候只要设置mimeMap节点中的fileExtension文件扩展名属性和mimeType这个MIME类型属性(点击此链接查看常用MIME类型)。
  大概的代码如下(代码中添加的扩展名和MIME类型只是作为示例):
  

<system.webServer>  
<staticContent>
  
<remove fileExtension=".woff" />
  
<remove fileExtension=".xap" />
  
<remove fileExtension=".xaml" />
  
<remove fileExtension=".apk" />
  

  
<mimeMap fileExtension=".woff" mimeType="font/x-font-woff" />
  
<mimeMap fileExtension=".xap" mimeType="xapapplication/x-silverlight"/>
  
<mimeMap fileExtension=".xaml" mimeType="application/xaml+xml"/>
  
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" />
  
</staticContent>
  
</system.webServer>
  
页: [1]
查看完整版本: [转发]如何在ASP.NET的web.config配置文件中添加MIME类型