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没有离开页面。行为是设计的。别担心

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....