Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting MIME type in asp.net

Tags:

asp.net

I have a site and in the Chrome inspector, I get this:

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

Where do I setup the MIME types in the asp.net framework (not through the IIS console) so that I remove this warning? I'm using a font I downloaded from font squirrel with a .ttf file extension.

Thanks.

like image 485
frenchie Avatar asked Sep 22 '11 03:09

frenchie


1 Answers

Ok, No access to IIS:

The key here is instead of linking to your font file in the html or css, you create a asp.net document that sets its own mime type and then sends the contents of the font file.

A sample page load function of myfont.aspx: (completed with your appropriate data)

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

Then link to myfont.aspx

This is a technique that can be used for any different file type too: Intelligently serve up images through myimage.aspx, generate csv files, whatever.

Here are a few sources of varying technicality:

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

like image 95
Michael Jasper Avatar answered Sep 19 '22 14:09

Michael Jasper