Chrome显示“已取消”成功下载文件(200状态) [英] Chrome showing "canceled" on successful file download (200 status)
问题描述
不知道这是否是一个实际的问题,但是我正在ASP.NET中编写一个文件,即使文件总是成功地通过,在Chrome的开发者工具网络标签中,我总是看到这行红色,标记为已取消。
Not sure if this is an actual problem or not, but I'm writing a file out in ASP.NET, and even though the file always successfully goes through, in Chrome's developer tools, network tab, I always see the line in red, marked "Canceled".
我已经尝试了很多方法,为了简单起见,我用一个简单的文本文件来尝试,但它是对于PDF和其他文件类型也是如此。
I've tried lots of ways of doing this - for simplicity, I'm trying this with a simple text file, but it's true for PDF and other file types as well.
WebForms:我已经尝试了很多以下组合:
WebForms: I've tried it with lots of combinations of the following:
Response.Clear();
// and/or/neither
Response.ClearHeaders();
// with and without this
Response.Buffer = true;
Response.Charset = "";
// or/neither
Response.Charset = "utf-8";
// application/pdf for PDF, also tried application/octet-stream
Response.ContentType = "text/plain";
// with and without this
Response.AddHeader("Content-Length", bytes.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=1.txt");
// bytes is the UTF8 bytes for a string or the PDF contents
new MemoryStream(bytes).WriteTo(Response.OutputStream);
// or
Response.Write("12345");
// any combination of the following 3, or none at all
Response.Flush();
Response.Close();
Response.End();
MVC(2和3,尚未尝试4):
MVC (2 and 3, haven't tried 4):
byte[] fileContents = Encoding.UTF8.GetBytes("12345");
return File(fileContents, "text/plain", "1.txt");
// or
return File(@"C:\temp\1.txt", "text/plain", "1.txt");
它始终是一样的 - 文件通过只是罚款,但开发工具显示我:
It's always the same - the file goes through just fine, but dev tools shows me this:
我是认为只是忽略它,继续生活,但红色只是打扰了我。任何想法如何处理?
I'm thinking of just ignoring it and moving on with life, but the red just bothers me. Any idea how I can deal with that?
推荐答案
这只是意味着chrome没有离开页面。行为是设计的。不要担心。
This just means that chrome didn't navigate away from the page. The behavior is by design. Don't worry about it.
这篇关于Chrome显示“已取消”成功下载文件(200状态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!