首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >文件下载成功时,Chrome显示“已取消”(200状态)

文件下载成功时,Chrome显示“已取消”(200状态)
EN

Stack Overflow用户
提问于 2013-03-14 02:10:38
回答 1查看 2.7K关注 0票数 17

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

我已经尝试了很多方法--为了简单起见,我尝试了一个简单的文本文件,但它也适用于PDF和其他文件类型。

WebForms:我尝试过以下几种方式的组合:

代码语言:javascript
复制
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):

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

它总是一样的--文件运行得很好,但是dev tools向我展示了以下内容:

我正在考虑忽略它,继续生活,但红色就是困扰着我。你知道我该怎么处理吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-14 02:13:50

这只意味着chrome并没有离开页面。这种行为是设计出来的。不必为那事担心了。

票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15393210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档