Chrome成功下载文件后显示"已取消"(200状态)

Joe*_*nos 17 asp.net asp.net-mvc download

不确定这是否是一个实际问题,但我在ASP.NET中编写了一个文件,即使该文件总是成功通过,在Chrome的开发人员工具网络选项卡中,我总是看到该行为红色,标记为"已取消".

我已经尝试了很多方法 - 为简单起见,我正在尝试使用简单的文本文件,但对于PDF和其他文件类型也是如此.

WebForms:我已尝试过以下几种组合:

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();
Run Code Online (Sandbox Code Playgroud)

MVC(2和3,还没试过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");
Run Code Online (Sandbox Code Playgroud)

它总是一样的 - 文件通过很好,但开发工具告诉我这个: 开发工具网络输出

我只想忽视它并继续生活,但红色只是困扰我.知道如何处理这个问题吗?

Dan*_*Dan 18

这只是意味着chrome没有离开页面.行为是设计的.别担心.