views:

33

answers:

2

i have an action that return a file content. i added:

Response.AddHeader("Content-Disposition", "attactment; filename:\"" + survey.File + "\"");

so that the image would be opened in another tab/page, gets opened in the current tab/page.
whats wrong with the header?

A: 

You cannot control browser's tab behaviour by using HTTP headers - there is nothing in your code that affects this.

What might help you is changing HTML code that points to your download - if you are using tag you can set its target attribute to _tab or _blank and it will work in many browsers.

Alex T.
Am I wrong in anything? Why am I minussed?
Alex T.
+1  A: 

The content-disposition header instructs the user agent how it should present the data, and it is usually used when serving up binary data (as opposed to plain text). When set to "attachment", the display of the content is contingent upon further action of the user. In other words, the user should receive a prompt and must decide what to do with the content (usually given an "Open" or "Save" option).

You can not programmatically force a hyperlink to open up in a new tab. Even if you could, you should not. This behavior should be controlled by the user agent. As a user, when I want to open something in a new tab, I use the mouse-wheel-click because that is how my browser is configured.

Josh Stodola