1

失敗 - ネットワーク エラー

Chrome デバッガー ウィンドウ

スクリーンショット 2 はデバッガー ウィンドウの情報です。以下はファイルのダウンロードに使用されるコードです。Visual Studio の Chrome エミュレーターでは正常に動作していましたが、コードを展開すると動作しなくなりました。同じコードが別の場所で使用されており、そのコードは正常に機能しますが、なぜこれが機能しないのかわかりません。

    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();
    }
4

1 に答える 1

2

解決策が見つかりました。転送エンコーディングは でしたchunked。これは content-length ヘッダーをサポートしていないため、転送エンコーディングを に指定する必要がありますidentity

System.Web.HttpContext.Current.Response.AddHeader("Transfer-Encoding", "identity")
于 2016-10-17T20:53:33.660 に答える