2009-12-18 5 views
1

MVC 컨트롤러에반환하는 데 오랜 시간이 걸리는 MVC 작업

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

     return filePath; 
} 

MVC 컨트롤러가 있습니다. 그리고 어떤 이유로 리턴 라인에 도달 할 때 20 초 이상 걸립니다.

pdfBuffer는 정상적으로 작동합니다. VS에서 실행하면 문제가 없지만 IIS 6에 배포하면 느리게 실행됩니다.

누구나 알 수 있습니까?

답변

2

, 응답 시간을 개선하는 것 유일한 것은 같은 파일을 생성하는 클래스에서 직접 응답을 전송했다 :

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

하지만 이렇게하면 당신은 우리가 단지를 보내는 것을 방지하기 위해 ActionMethod에서 "not all code paths return a value"을 얻을 것이다 : 우리는 방법에 직접 요청을 종료하기 때문에

return new EmptyResult(); 

이 마지막 줄이 실제로 실행되지 않습니다.

+0

완벽한, 감사합니다 .-) – Coppermill

관련 문제