Auto detect content-type

  • Thread starter Grzegorz Kaczor
  • 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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top