有一个名为“360 secure browser”的桌面浏览器'。他们在中国有相当大的市场份额,我们需要支持他们。
上面写着layout engine is Trident (IE) ,这正是我所期望的,但我现在无法验证这一点(在 Mac 上!)。
原因是我有一些表单可以启动下载,将字节流传输到客户端,并且它们可以在其他主要浏览器中工作。导致问题的代码如下或类似。这是做错了什么我没有注意到的事情吗?字节流通常在 50-100KB 左右,我们还没有遇到任何问题。
- 调用此代码是为了响应 PostBack 事件(例如,单击网格中的按钮等)
- 使用文件中的字节流调用此函数,在内存中生成或从数据库读取。
功能:
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;
}
有人有支持此浏览器的经验吗?在 google 上用英语搜索时,我找不到任何相关信息。没有规范,没有文档,什么都没有。我得去百度找资料,我看不懂那种水平的中文!
编辑:
问题显然出在 360 使用的下载器上。不过,我想知道流代码中是否应该更改某些内容。我缺少的 header 或其他内容。
- 这只发生在小文件上。相同的页面,更大的下载 = 没有问题。
- 更改为内置 IE 下载程序后问题就会消失。
最佳答案
您好,我在360安全浏览器上尝试了您的代码。它对我有用。我在下面编辑了一点是我的代码。 注:据我所知,360安全浏览器使用的是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;
}
关于asp.net - 有关于中文 '360 secure browser' 的信息吗?下载我正在流式传输的文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10040630/