1

アクションを持つMVCコントローラーがあります

public ActionResult GeneratePDF(string id)
{
      FileContentResult filePath = this.File(pdfBuffer, MediaTypeNames.Application.Pdf);

      return filePath;
}

そしてなぜかリターンラインに到達するまでに20秒以上かかっています。

pdfBuffer は正常に動作しており、VS で実行すると問題ありませんが、IIS 6 にデプロイすると動作が遅くなります。

理由を知っている人はいますか?

4

1 に答える 1

2

XLS と PDF にエクスポートしようとしたときに同様の問題が発生しました。応答時間を改善するように見える唯一のことは、次のようなファイルを生成するクラスから直接応答を送信することでした。

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + file + ".pdf");
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
HttpContext.Current.Response.Flush();
stream.Close();
HttpContext.Current.Response.End();

しかし、これを行うと"not all code paths return a value"、ActionMethod から が取得されます。これを回避するために、以下を送信するだけです。

return new EmptyResult();

この最後の行は、メソッドで直接リクエストを終了するため、実際には実行されません。

于 2009-12-18T14:59:14.703 に答える