473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File Download does not continue after IE Security warning

Hello,

I am completely stuck here. Basically, I am serving a file to the user by sending it using Respnse.BinaryWrite. I am also sending this on a redirected page so as not to destroy the Response stream of the webpage which fired the filedownload. This works perfect on my development machine, it also works perfect on Firefox.

However, if I publish to my test server, on IE 8 (and 7 I presume) a security warning bar appears (does not appear in dev mode on my pc), asking the user to accept or decline the file. Now the not-so-funny thing: If the user accepts, the file is NOT served, I just get back to my main webpage. If the user tries a second time to get the file the security question will NOT pop up again and the file is served.

How can I make sure the file is served in the first instance if the user accepts the security warning and wants to download?

Thank you very much for your support, greatly appreciated!

Marc

Code used:

Expand|Select|Wrap|Line Numbers
  1. HttpContext.Current.Response.Clear()
  2. HttpContext.Current.Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", Session("FileName")))
  3. HttpContext.Current.Response.AppendHeader("Content-Length", myReportData.Length.ToString())
  4. HttpContext.Current.Response.ContentType = "application/pdf"
  5.  
  6. HttpContext.Current.Response.BinaryWrite(myReportData.ToArray)
  7.  
  8. HttpContext.Current.Response.Flush()
  9. HttpContext.Current.Response.End()
Jun 8 '10 #1
7 6269
Frinavale
9,735 Expert Mod 8TB
Could you please elaborate on the "Response.Redirect" technique that you're using? I've never tried doing that before...I've always just used an iFrame (setting the source to a page that serves the file) to "automatically download" when then request returns to the browser.

-Frinny
Jun 8 '10 #2
Hello Frinny,

Thank you for your response.

I simply redirect to a page as follows:

HttpContext.Current.Response.Redirect("FileDownloa d.aspx")

That page, during the Page.Load event sends the file to the user. And there is the prob that the security message pops up, which, after the user decides to continue, does apparently reload the page and drop my download.

In the meantime I have found a workaround, but its not the best solution. Basically, the problem appears that IE will do a page reload when changing the security setting (it appears to change the currently applicable setting if the user says to continue). There might be a flaw in my code logic that prevents the file from being served if a page reload is caused by IE.

However, what works is to put a simple button on the FileDownload page, and then serve the file during the buttons click event. It appears that IE recognizes that it is the client who enacted the buttons click event during which the file is sent, and therefore assumes that all must be fine. If i serve the file directly during the load event the security warning appears.

That said, I still would very much like to see what I can do to avoid having the user click on a button.

Thanks!
Jun 8 '10 #3
Frinavale
9,735 Expert Mod 8TB
If you want to, you could try the iFrame trick that I use all the time...
It gets rid of the need to click the button...and it's pretty simple :)
Jun 8 '10 #4
Hello Frinny,

I am pretty new to ASP.NET. If its not asked too much could you share some code here? Please note that I am not actually CREATING a real file on the server which i could serve, I am creating it on the fly and just serve it as a bit array. If that still works for your IFrame approach I would love to see some code snippets! Thanks pal!
Jun 8 '10 #5
Frinavale
9,735 Expert Mod 8TB
It's simple. I'm not sure if you know what an iframe is so here's a quick explanation. An iframe is an like "embedded window" that can be used to display HTML from other pages embedded within your page. In this case we don't want to display any HTML data but we want to take advantage of having a "hidden" window within the browser so that when you're ready to download the information it will happen on the same page (without having to open a new window etc to do this)

The first step you need to do is add an iFrame to the page and give it an id that you can refer to and set the style to display:none (which will hide the iframe):

Expand|Select|Wrap|Line Numbers
  1. <iframe id="RetrieveFile" style="display:none"></iframe>
Currently the iframe isn't displaying anything because we haven't set the src attribute to any page in particular. It doesn't matter anyways because you can't see the iframe with the display:none style.

Ok, now let's say the user clicks a button...you do some validation stuff server side and determine that you should allow the user to download the file.

In this case you want to set the src attribute of the iframe element.

Apparently...I don't have an example of how to do this in server side code....

But you could either add JavaScript to the page that retrieves the iframe element and sets the src property depending on a value in a hidden field...oh I'm going to fast here. In this case you would also need to add an ASP.NET HiddenField control to the page. HiddenFields are accessible in both JavaScript and your server code. So, in your server code you would set the value of the hidden field to True (or something) and in the JavaScript code you would retrieve this value and check whether or not to set the src of the iframe to download the page.

Or you could try setting the iframe to runat="server" and see if you can set the src property there. This is probably the MUCH easier way to accomplish this.

I've only taken the JavaScript approach because typically I'm messing around with some Ajax control and this code is in the corresponding JavaScript object.
Jun 8 '10 #6
wohow.. you lost me somewhere ;) still, i will delve into IFrames and hopefully be able to sort it out. I would love not to have to redirect. thank you very much for your help, greatly appreciated !!
Jun 8 '10 #7
Hi Frinny,

I just wanted to let you know that all works perfect using the IFrame approach you mentioned. Especially, on a live server IE will NOT display a file download security warning. This is because the file download is actually triggered during a client invoked postback (the client clicked on the download button).

Thank you very much for your help, pal, this is awesome! I learned something.

For other reading this thread, here is what I did:

On the page where you have your download button:

- Put your download button into a dedicated UpdatePanel
- The use of the UpdatePanel will ensure you are able to catch start and end of the download process. In my case I am using a DevExpress LoadingPanel to show progress.

Use the following code:

Expand|Select|Wrap|Line Numbers
  1.     <asp:ScriptManager ID="ScriptManager1" runat="server" 
  2.            AsyncPostBackTimeout="120"> // make sure you give the whole process enough time!!
  3.         </asp:ScriptManager>
  4.  
  5.         <script type="text/javascript">
  6.             var prm = Sys.WebForms.PageRequestManager.getInstance();
  7.             prm.add_initializeRequest(prm_InitializeRequest);
  8.             prm.add_endRequest(prm_EndRequest);
  9.  
  10.             function prm_InitializeRequest(sender, args) {
  11.                 LoadingPanel_client.Show();  // this is a DevExpress component, but you can implement something else of your choice. It simply shows a 'Busy' Window.
  12.  
  13.                 var iframe = document.createElement("iframe");
  14.                 iframe.src = "FileDownload.aspx";
  15.                 iframe.style.display = "none";
  16.  
  17.                 // Add the IFRAME to the page.  This will trigger the FileDownload.aspx page to load now and during load create and send the file
  18.                 document.body.appendChild(iframe)
  19.             }
  20.  
  21.             function prm_EndRequest(sender, args) {
  22.                 LoadingPanel_client.Hide();
  23.                            }
  24.         </script>

Now, your FileDownload.aspx page can be completely empty as it is not going to display anyway. During the Page.Load event create or load your file and serve it with code similar to that:

Expand|Select|Wrap|Line Numbers
  1.         HttpContext.Current.Response.Clear()
  2.             HttpContext.Current.Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", "test.pdf"))
  3.             HttpContext.Current.Response.AppendHeader("Content-Length", repStream.Length.ToString())
  4.             HttpContext.Current.Response.ContentType = "application/pdf"
  5.  
  6.             'repStream.WriteTo(HttpContext.Current.Response.OutputStream)   // either works
  7.             HttpContext.Current.Response.BinaryWrite(repStream.ToArray)
  8.  
  9.  
  10.             HttpContext.Current.Response.Flush()   ' send the data now
  11.             HttpContext.Current.Response.End()
Jun 9 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Srikanth | last post by:
Hi I have a web page - in that i give a link to exe file. When the user clicks on the link the exe is supposed to be downloaded and executed in the user's system. (I am not writing any...
2
by: brian | last post by:
I have an asp.net intranet site created using vb.net codebehind. I have 4 vb.net exe's located on my IIS server and can be accessed by hyperlink. Each time these links are opened and the exe is...
5
by: Hatim Ali | last post by:
Hello folks, I've integrated my ASP.NET website with a portal on web. My website opens in a frame provided by the web portal. The portal uses https protocol. Now when i open my website IE...
5
by: Bala | last post by:
Hi I displaying my pdf files ( F:\test\test1\test.pdf - for example file path) on datagrid for user download. when I right clik the link and its show like this file:///F:/test/test1/test.pdf....
13
by: bmurphy | last post by:
Last week after much searching, I found the answer to my problem in this newsgroup. I can't find the thread from which I got my solution, but I wanted to report back what worked. When the site...
1
by: Cindy H | last post by:
Hi I used the code below to automatically open a pdf file when the user clicks on a menu option. It works great on local machine, but when I uploaded it to hosting site and then tried it, I...
2
by: Charles Mifsud | last post by:
Hi all, We have an asp.net 2.0 page with a button. On clicking the button we redirect to another page which downloads a file. When we deploy on the web server we are gretting a security...
3
by: bfiser | last post by:
Good morning everyone. I have an issue with a page I developed using ASP. On my page I have active (or is it dynamic) hyperlinks to photos of employees based on their employee number. When I...
7
by: bloukopkoggelmander | last post by:
Morning all I have a rather strange problem I have been trying to solve for a few days now. I am using Namo Web Editor for our local Intranet. All static pages with fixed URL's. I have a few links...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.