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屋!