不确定这是否是一个实际的问题,但我正在用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", "text/plain", "1.txt");
它总是一样的--文件运行得很好,但是dev tools向我展示了以下内容:
我正在考虑忽略它,继续生活,但红色就是困扰着我。你知道我该怎么处理吗?
发布于 2013-03-14 02:13:50
这只意味着chrome并没有离开页面。这种行为是设计出来的。不必为那事担心了。
https://stackoverflow.com/questions/15393210
复制相似问题