In an ASP.Net MVC application of mine, I have a backend generating reports. Once the reports is generated, the user can download it with a link calling an action to serve it. However, I feel like the action to serve files is kinda slow (4 to 8 seconds), where the other action are instantaneous in comparaison.
Here is the code that does the serving
// 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 : I can't switch to a direct file access for security reasons.