在asp.net中设置MIME类型

时间:2011-09-22 03:32:46

标签: asp.net

我有一个网站,在Chrome检查器中,我得到了这个:

Resource interpreted as Font but transferred with MIME type application/octet-stream.

我在哪里设置asp.net框架中的MIME类型(而不是通过IIS控制台),以便我删除此警告?我正在使用从font squirrel下载的带有.ttf文件扩展名的字体。

感谢。

1 个答案:

答案 0 :(得分:4)

好的,无法访问IIS:

这里的关键是不是链接到html或css中的字体文件,而是创建一个asp.net文档,设置自己的mime类型,然后发送字体文件的内容。

myfont.aspx的示例页面加载功能:(使用适当的数据完成)

Response.ContentType = "YourMimeType/Type"
Response.AddHeader("Header Name", "Header value")
Response.WriteFile("font.ttf")
Response.End()
Response.Clear()

然后链接到myfont.aspx

这种技术也可以用于任何不同的文件类型:通过myimage.aspx智能地提供图像,生成csv文件等等。

以下是不同技术性的一些来源:

http://weblogs.asp.net/stoianbucovich/archive/2008/05/26/using-http-header-to-send-file.aspx

http://www.xefteri.com/articles/show.cfm?id=8

http://forums.asp.net/p/1204802/2109808.aspx