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.
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.
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.
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.
Related
Hello I have an editable pdf that needs to be directly downloadable. Embedding is a bit tricky so I've decided to just have it downloaded directly to user's computers. It's on a Wordpress site and I have it downloading directly but I am still able to open it in a browser.
Can someone assist?
Thank you
This is a duplicate question. As noted at (HTML) Download a PDF file instead of opening them in browser when clicked HTML5 provides an attribute that forces the browser to download files when clicked; but it's considered to be a less than desirable practice. How a user interacts with a PDF should be left up to the user.
I intend to use ASP.NET Server.TransferRequest to send a file to the browser without the browser knowing the actual path of the file being downloaded. For example, the address download.aspx?id=123 should result in the browsers Save dialog popping up.
When I use Server.TransferRequest to "redirect" to, say, a PDF file, the contents of the PDF file is sent to the browser; however, the content is shown in the browser window as - not surprisingly - unintelligible text.
I think there should be some headers attached to the response to force the browser to download the file, but "Content-disposition" header doesn't do the trick.
Any ideas on how to do this?
I have some Word files which need to have hyperlinks. The hyperlinks go to an htm file with an anchor, but that htm file isn't provided via a direct url for security reasons. Rather it is linking to a ashx handler file that retrieves the file and does an response.write to show the html file in the browser. Before it does this, though, it checks to back sure that there's a valid session, and if there isn't then it just redirects to the login page. This works fine when linking from within the ASP.Net site, but when I link to it from a local MSWord file, it apparently doesn't know there's a valid session (even though I've logged in in the browser), and redirects to the login page. Is there any way around this? For compatibility these Word documents need to be in Word 97-2003 format unfortunately...
No. This won't work.
Opening the word file outside of a browser and clicking on the link is going to start a brand new session; regardless of whether you currently have a browser window opened on the site.
Because a new session is starting, the web server will assume you aren't logged in at all. Which, technically, you aren't.
I have the following scenario, and I wanted suggestions on what is the best way to handle this. My web app (ASP.NET 2.0 / IIS 6) generates PDF files, and I have a results page with links to those PDFs.
Now, I noticed that if I visit the results page, click on a PDF file (it opens in a new window), then re-generate the PDF file, and click on the same link in the results page, the OLD PDF is shown, instead of the new one. I had to delete the temporary internet files in order to see the new one.
So, since I'm NOT serving an ASPX that actually writes the PDF (and I do not want the Save dialog to show), but straight linking to the PDF file, I want to know what the best way to make sure the user always sees the latest file in the server, not a cached version.
I'm guessing adding no-cache headers is out of the question. But the PDF request would still go through an HTTP handler, so I'd like to know if I should create a specific HTTP handler to intercept requests for PDFs, or if i should do this at the IIS level...however I dont necessarily want to avoid caching ALL PDF's on that site.
Any suggestions? Thanks in advance for the help.
If your link to the pdf document had a unique querystring appended I believe that would prevent caching. Time in ticks is a good one to use, eg:
string.Format("{0}?t={1}", pdfFileUrl, DateTime.Now.Ticks);
I just had a similar issue. I have my page allows users to input data and generate new a pdf file Save clicked. The new pdf file overwrites the old one. In IE8, when user click the pdf link after the Save, the old pdf will always showed (user need to clear the cache to display the new one).
After hours of searching, I found that in IIS6, go to 'Output Caching', add a new cache rule with file extension '.aspx', tick both 'User-mode caching' and 'Kernel-mode caching' then under both options, select 'Prevent all caching'. This is working for me!
The fact the clearing your temporary internet files gave you the new version shows the browser is the source of the cache. You could turn iis caching off but that wouldn't stop proxies caching the document. If you need to be 100% sure that the user sees that latest version, I suggest using a query string value to cause the url to be different. The query string could be the pdf generation timestamp.
I'm still rebuilding old ASP to new and iframing certain things that take up too much time.
I'm stuck at a search function that normally returns an excel file (browser asks save or open). the result page for this is now iframed but it does not seem to propagate the file anymore, so no more save-file popup.
I must add that this iframe is being filled through a custom httphandler that posts to the old pages based on certain criterie, the searchcriteria in this case.
does anyone have an idea on how I could make the excel propagate once again?
The way to ensure you get a save-file prompt and not a page, do the following:
Open the file in ASP
Send the MIME header for Excel
Stream out the file from ASP
You may also choose to hold the files outside of the web root so they cannot be downloaded directly.
Here are a few examples: 1 2 3
This may come in handy as well:
How to output an Excel *.xls file from classic ASP
It *seems* like a security issue. What happens if you open the URL which is being loaded in the IFrame in a new browser? To confirm it, you can try opening the URL, and see what happens.