Note that there are some explanatory texts on larger screens.

plurals
  1. POStreamed HTML files have no Open option in IE
    primarykey
    data
    text
    <p>We have some kind of file explorer in our ASP.NET web application.</p> <p>It can stream files of various types that reside on an external towards the user. Now everything is working fine, but now they want to stream HTML files and they give issues.</p> <p>When I want to stream a HTML file in IE, the download prompt does not give me the option to open it, it only has the Save and Save As options.</p> <p>I've been googling for days, but the only thing I could find is how to turn off the Open button, but I want it to be there while it isn't by default. Both Firefox and Chrome do have an Open option in their download prompts.</p> <p>The code on the external server to stream the files is as followed:</p> <p>Note: file is an instance of our own file object that contains info, like path, filename, flags,... about the file we ant to stream</p> <pre><code> System.IO.FileInfo fileInfo = new System.IO.FileInfo("C:\\\\MyFolder\\" + file.FullName); if (fileInfo.Exists) { System.IO.FileStream fs = new System.IO.FileStream("C:\\\\MyFolder\\" + file.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read); string filename = file.Name.Replace(" ", "_"); page.Trace.IsEnabled = false; page.Response.Expires = 0; page.Response.Buffer = true; page.Response.Clear(); page.Response.ContentType = MimeTypeParser.GetMimeType(fileInfo.FullName); //Gets the Correct content type: "text/html" in this case page.Response.AddHeader("Content-Length", fs.Length.ToString()); page.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); int bufferSize = 8192; // default to 4K, may want to use 8K instead byte[] bytes = null; bytes = new byte[bufferSize + 1]; int read = 0; //Helper to read the bytes to the response steamer while ((InlineAssignHelper(read, fs.Read(bytes, 0, bytes.Length))) != 0) { page.Response.OutputStream.Write(bytes, 0, read); } page.Response.OutputStream.Flush(); //close off response or else you get corrupted files fs.Close(); page.Response.End(); } else { page.Response.StatusCode = 404; page.Response.End(); } </code></pre> <p>On the application itself the following code is used to get the data from the streamer and push it to the response to the client:</p> <pre><code>public void StreamFile(int id, System.Web.HttpRequest clientRequest, System.Web.HttpResponse clientResponse) { try { OurDomain.File file = OurBLL.FileService.GetFile(id); if (file != null) { string url = "http://FilestreamingServer?StreamFile.aspxid=" + file.Pkey + "&amp;userName=" + userName; Uri uri = new Uri(url); System.Net.WebRequest request = System.Net.HttpWebRequest.Create(uri); request.Method = System.Net.WebRequestMethods.Http.Get; System.Net.WebResponse response = request.GetResponse();// 1st code block on the other server is invoked here clientResponse.ContentType = response.Headers["Content-Type"]; clientResponse.AddHeader("Content-Length", response.Headers["Content-Length"]); clientResponse.AppendHeader("Content-Disposition", response.Headers["Content-Disposition"]); int bufferSize = 8192; // default to 4K, may want to use 8K instead byte[] bytes = null; bytes = new byte[bufferSize + 1]; System.IO.Stream stream = response.GetResponseStream(); int read = 0; while ((InlineAssignHelper(read, stream.Read(bytes, 0, bytes.Length))) != 0) { clientResponse.OutputStream.Write(bytes, 0, read); } clientResponse.OutputStream.Flush(); OurBLL.LogService.WriteDownloadLog(file); //close off response or else you get corrupted files clientResponse.End(); } } catch (System.Threading.ThreadAbortException ex) { //is due to response.end call. } catch (Exception ex) { //Log exception } } </code></pre> <p>When I look at the response in F12, I see the expected headers in the response:</p> <ul> <li>Response: HTTP/1.1 200 OK Pragma: no-cache </li> <li>Content-Type: text/html</li> <li>Server: Microsoft-IIS/7.5</li> <li>Refresh: 3580</li> <li>Content-Disposition: attachment; filename=Test.html</li> <li>X-Powered-By: ASP.NET</li> <li>Date: Wed, 11 Dec 2013 11:19:19 GMT</li> <li>Content-Length: 222</li> </ul> <p>As far as I know everything is there to show a regular download prompt with all options.</p> <p>What am I missing?</p> <p>Is there a header tag to force the prompt to turn on the Open option, like you have "X-Download-Options: noopen" to turn it off?</p> <p>I know you can open the file in the browser by adding "inline" in the Content-Disposition header instead of attachment, but that's no option cause that'll open the page in the current window and I have to keep the file browse open.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload