Ошибка загрузки Chrome - ошибка сети
Снимок экрана 2 - это информация об окне отладчика, а ниже - код, используемый для загрузки файла, он хорошо работал в визуальной студии Chrome Emulators, но когда я развернул код, он перестал работать. тот же код используется в другом месте, и тот работает нормально, не уверен, почему этот не работает.
public ActionResult DownloadFile(decimal document_id)
{
var DocumentForDownload = riskProfile.GetDocumentForDownload(document_id, isfordownload: true);
byte[] byteArray = DocumentForDownload.DOCUMENT;
var filename = DocumentForDownload.DOCUMENT_NAME + "." + DocumentForDownload.EXTENSION;
string mimeType = "application/" + DocumentForDownload.EXTENSION;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.AddHeader("content-length", byteArray.Length.ToString());
System.Web.HttpContext.Current.Response.ContentType = "application/" + DocumentForDownload.EXTENSION;
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filename);
System.Web.HttpContext.Current.Response.Charset = "utf-8";
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
System.Web.HttpContext.Current.Response.BinaryWrite(byteArray);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.OutputStream.Close();
System.Web.HttpContext.Current.Response.End();
System.Web.HttpContext.Current.Response.Close();
return new EmptyResult();
}
1 ответ
Решение
Нашел решение, кодировка передачи была chunked
, который не поддерживает заголовок content-length, поэтому нам нужно указать кодировку передачи для identity
,
System.Web.HttpContext.Current.Response.AddHeader("Transfer-Encoding", "identity")