Download known extensions
am 19.11.2007 09:27:51 von Stan SR
Hi,
How to configure IIS 6 to allow to the users to download files with known
extensions.
I set up a website within IIS, where I store uploaded files.
My problem is when a user selects a file like blabla.mp3 I would like to get
the standard popup window asking to user if she wants to save or run the
file.
Right now, if it's a mp3 file, it starts with the associated program. Same
thing with a pdf file, it opens the file within the acrobat reader.
Any help ?
Stan
Re: Download known extensions
am 19.11.2007 13:17:21 von David Wang
On Nov 19, 12:27 am, "Stan SR" wrote:
> Hi,
> How to configure IIS 6 to allow to the users to download files with known
> extensions.
> I set up a website within IIS, where I store uploaded files.
> My problem is when a user selects a file like blabla.mp3 I would like to get
> the standard popup window asking to user if she wants to save or run the
> file.
> Right now, if it's a mp3 file, it starts with the associated program. Same
> thing with a pdf file, it opens the file within the acrobat reader.
> Any help ?
> Stan
For the download directory(s), create a * MIME Type and set it to
application/octet-stream
This should make all browsers show a "save" dialog on download.
You won't have a "run" option with this approach because the browser
won't know what to run it with (or else it would have automatically
started the associated program instead of showing "Save").
Remember, this is ultimately a client-side problem. The server does
the same thing to serve the file for download. It is the client that
decides between "Save" or "Run", and the client decides based on the
Content-Type (controlled by MIME Type on the server). When you use
application/octet-stream, it tells the browser "it's just a bunch of
bytes, no associated program", so the browser only allows "Save". If
the client gets a Content-Type that it has an associated program for,
it controls whether to save/run it. IIS has no control whatsoever on
the client-side decision, and there is no MIME Type that tells the
client "offer a save or run option for this resource".
//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//
Re: Download known extensions
am 23.11.2007 12:10:58 von Andrew Morton
Stan SR wrote:
> How to configure IIS 6 to allow to the users to download files with
> known extensions.
If you use, say, ASP.NET to deliver the files (e.g
download.aspx?file=song.mp3) then you can add a content-disposition header
such that it makes the browser more likely to offer to save the file, whilst
keeping the correct content-type (which you'd have to set in code too):
Response.ContentType = "audio/mpeg"
Response.AddHeader("content-disposition", "attachment; filename=" &
yourFilename)
Response.WriteFile(Path.Combine(HttpContext.Current.Request. PhysicalApplicationPath,
yourFilename))
....obviously with checks to allow downloading of only permitted files.
Andrew