Auto detect content-type

  • Thread starter Thread starter Grzegorz Kaczor
  • Start date Start date
G

Grzegorz Kaczor

Hello,

I wanted to use Response.TransmitFile to return an image instead of a
HTML page. Under IE everything works well, but under Mozilla/Firefox the
image is treated as it were text/html.

When I set up content-type in response to image/jpeg everything works well.

But I would like to send any file instead of an image and thus I cannot
always know the proper content type. Is it possible to "autodetect" a
file content type? Or make IIS perform an "invisible redirect"
(something like Server.Execute but with local path name instead of URL)
so that default IIS mechanisms of content-type detection were used?

Thanks
Grzegorz Kaczor
 
MIME types are usually recognized by the file extension. When the file
extension doesn't match the MIME type, the Response.ContentType header must
be set, to let the browser know. So, if you want to "autodetect" the MIME
type, you're going to have to do one of the following:

1. Read the file extension
2. Know what the type of file is by some other means

Then you have to set the Response.ContentType to that MIME type in the
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Back
Top