2

There is a desktop browser called '360 secure browser'. They have a fairly large share of the market in China, and we are required to support them.

It says the layout engine is Trident (IE), which is what I expected, but I can't verify that right now (on a mac!).

The reason for this is that I have some forms that kick off a download, streaming bytes to the client, and they work in the other major browsers. The code that causes the issue is below, or similar. Is this doing something wrong that I don't notice? The byte streams are usually on the order of 50-100KB, and we haven't had issues with it yet.

  • This code is called in response to a PostBack event (eg, button click in a grid, etc)
  • This function is called with bytestreams from files, generated in memory, or read from db.

The function:

public static bool DownloadStream(byte[] packageStream, string fileName) {
    var response = HttpContext.Current.Response;
    response.Clear();
    response.AddHeader("Accept-Ranges", "bytes");
    response.AddHeader("Content-Disposition", "inline; filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
    response.AddHeader("Content-Length", packageStream.Length.ToString());
    response.ContentType = "application/xlsx";
    response.BinaryWrite(packageStream);
    response.Flush();
    HttpContext.Current.ApplicationInstance.CompleteRequest();
    return true;
}

Does anyone have any experience supporting this browser? I can't find any information on it when searching in english on google. No specs, no docs, nothing. I have to go to Baidu to find info, and I can't read that level of chinese!

EDIT:

The issue is with the downloader that 360 uses, apparently. I would like to know if there is something that should be changed in the streaming code, though. A header that I am missing, or something else.

  • This is only happening for small files. Same page, bigger download = no issues.
  • Changing to the built-in IE downloader causes the issue to go away.
Andrew
  • 8,322
  • 2
  • 47
  • 70
  • If there is a better place for this question, please just tell me. I already looked, and no other SO that I know of apply. – Andrew Apr 06 '12 at 07:46

1 Answers1

2

Hi i tried your code on 360 secure browser. it work for me. and i edit a little bit below is my code. Note: As i know, 360 secure browser is using IE Core.

   protected void Page_Load(object sender, EventArgs e)
    {
        DownloadStream(StreamFile(@"C:\Users\My\Desktop\test2.xlsx"), "test.xlsx");
    }

    private byte[] StreamFile(string filename)
    {
        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);

        // Create a byte array of file stream length
        byte[] Data = new byte[fs.Length];

        //Read block of bytes from stream into the byte array
        fs.Read(Data, 0, System.Convert.ToInt32(fs.Length));

        //Close the File Stream
        fs.Close();
        return Data; //return the byte data
    }


    public static bool DownloadStream(byte[] packageStream, string fileName)
    {
        var response = HttpContext.Current.Response;
        response.ClearContent();
        response.ClearHeaders();
        response.AppendHeader("Accept-Ranges", "bytes");
        response.AppendHeader("Content-Disposition", "inline; filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
        response.AppendHeader("Content-Length", packageStream.Length.ToString());
        response.ContentType = "application/xlsx";
        response.BinaryWrite(packageStream);
        response.Flush();
        response.End();
        return true;
    }
skywills
  • 130
  • 6
  • Thanks for the full sample, for others :) The change I see that is important is just `ClearHeaders()`, which I did forget. #1) See http://stackoverflow.com/questions/1087777/is-response-end-considered-harmful for more background and why `CompleteRequest()` is recommended. #2) Use a `using(var fs=File.OpenRead()) {` *or variant* to be safe with the file handle. It will close it for you automatically. I didn't include the reading code because we get streams from file, from memory, from database, etc. Just keepin it simple. – Andrew Apr 06 '12 at 09:23
  • thanks for your info for the completeRequest(). Anyway the FileStream code i just put in for simply testing only. – skywills Apr 06 '12 at 09:36
  • Turns out that the issue is removed by changing the downloader from 360's built in one, to the IE native one. And it only fails for small files, for some reason. – Andrew Apr 08 '12 at 16:58