I currently have my web application setup to be able to serve files to the client. When the appropriate button is clicked to download a particular file, it sets a session variable and opens a pop-up window. This pop-up window is a .aspx file. The .aspx file grabs the file location based on the session variable, and then takes that file and serves it to the client with the provided code. The problem I believe is because of this line:
ion", "attachment; filename=" + fi.Name);
I believe IE is forcing the pop up closed because of security reasons, claiming that the file type is something other than .aspx which is what the page loading in the window is. If I comment out that line, the download works, except it doesn't give me the file I want, instead it has me download the .aspx file.
How can I get past this and have it so the window doesn't get forcibly closed so the download dialog box appears?
Also, this methodology works absolutely fine on a local intranet, which is also why it makes me believe it's a security reason that IE closes the window. Changing IE Security settings to resolve this issue is not an option.
Thank you for your assistance.
FileInfo fi = new FileInfo(filePath);
if (fi.Extension.ToLower() == ".msg")
Response.ContentType = "application/outlook";
else if (fi.Extension.ToLower() == ".doc")
Response.ContentType = "application/msword";
else if (fi.Extension.ToLower() == ".htm" || fi.Extension.ToLower() == ".html")
Response.ContentType = "text/html";
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fi.Name);