asp.net – Chrome在成功的文件下载(200状态)上显示“已取消”

不知道这是否是一个实际的问题,但是我正在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();

MVC(2和3,还没试过4):

byte[] fileContents = Encoding.UTF8.GetBytes("12345");
return File(fileContents,"text/plain","1.txt");
// or
return File(@"C:\temp\1.txt","1.txt");

它总是一样的 – 文件通过只是罚款,但开发工具显示我:

我正在考虑只是忽略它,继续生活,但红色只是困扰着我。任何想法如何处理?

解决方法

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

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...