在我的ASP.Net MVC應用程序中,我有一個後端生成報告。一旦生成報告,用戶就可以通過一個鏈接調用一個動作來下載它。但是,我覺得服務文件的動作有點慢(4到8秒),其他動作是比較即時的。服務文件作爲ASP.NET MVC操作的一部分很慢
這裏是做服務
// GET: /WS/Report/GetReport
[HttpGet]
public ActionResult GetReport(string fileName)
{
string path = Path.Combine(_reportGeneratedPath, fileName);
if (!System.IO.File.Exists(path))
return XmlMessage.Error("Report does not exist");
Response.ContentType = MimeMapping.GetMimeMapping(fileName);
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName));
Response.AddHeader("Content-Length", new FileInfo(path).Length.ToString());
Response.WriteFile(path);
Response.End();
return null;
}
PS代碼:我不能切換到出於安全原因的直接文件訪問。
這可能是有用的,http://stackoverflow.com/a/26023967/1166597 – OldTrain