Content-Disposition:What are the differences between "inline" and "attachment"?
Asked Answered
R

3

289

What are the differences between

Response.AddHeader("Content-Disposition", "attachment;filename=somefile.ext")

and

Response.AddHeader("Content-Disposition", "inline;filename=somefile.ext")

I don't know the differences , because when I use one or another I always get a window prompt asking me to download the file for both of them. I read the specs, but it is clueless.

Roma answered 8/9, 2009 at 17:13 Comment(5)
When the disposition type is inline, it does not typically have a filename.Pithos
Just for anyone’s info: filename can still be set with inline it is not standard though. Chrome, Firefox, IE and Opera respect the filename but Edge does not (2018).Ashelyashen
does anyone know of a resource for showing what the various browsers do with content-type, similar to caniuse for css?Huzzah
superuser.com/q/1277819/69300Student
Are you just checking in to see what disposition your disposition is in?Waxbill
R
335

Because when I use one or another I get a window prompt asking me to download the file for both of them.

This behavior depends on the browser and the file you are trying to serve. With inline, the browser will try to open the file within the browser.

For example, if you have a PDF file and Firefox/Adobe Reader, an inline disposition will open the PDF within Firefox, whereas attachment will force it to download.

If you're serving a .ZIP file, browsers won't be able to display it inline, so for inline and attachment dispositions, the file will be downloaded.

Rejection answered 8/9, 2009 at 17:18 Comment(1)
Just a quick correction: This behavior is sometimes different from a mobile context. Many app webviews will ignore attachment disposition and simply render it in browser if they can correctly identify the content-type.Egeria
O
35

If it is inline, the browser should attempt to render it within the browser window. If it cannot, it will resort to an external program, prompting the user.

With attachment, it will immediately go to the user, and not try to load it in the browser, whether it can or not.

Obscene answered 8/9, 2009 at 17:17 Comment(0)
D
12

It might also be worth mentioning that inline will try to open Office Documents (xls, doc etc) directly from the server, which might lead to a User Credentials Prompt.

see this link:

http://forums.asp.net/t/1885657.aspx/1?Access+the+SSRS+Report+in+excel+format+on+server

somebody tried to deliver an Excel Report from SSRS via ASP.Net -> the user always got prompted to enter the credentials. After clicking cancel on the prompt it would be opened anyway...

If the Content Disposition is marked as Attachment it will automatically be saved to the temp folder after clicking open and then opened in Excel from the local copy.

Domitiladomonic answered 29/4, 2013 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.