これが実際の問題かどうかはわかりませんが、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");
それは常に同じです-ファイルは問題なく通過しますが、開発ツールはこれを示しています:
無視して生きていこうと思っているのですが、赤が気になります。どうすれば対処できますか?