1

사용자가 원격으로 저장된 PDF 파일을 검색 할 수 있도록하는 간단한 HTTP 처리기가 있습니다. 놀랍게도,이 코드는 IE9에서 핸들러가 호출되었지만 IE8이 멈추어있을 때 잘 작동합니다. pdf를 올바르게 표시하려면 url을 다시 호출해야합니다.context.Response.Flush()는 IE8에서는 작동하지 않지만 IE9에서는 정상적으로 작동합니다.

웹에서 응답과 더 관련이 있는지 확인했습니다. 처음에는 응답이 제대로 끝나지 않았지만 아래 기사를 찾았습니다. http://blogs.msdn.com/b/aspnetue/archive/2010/05/25/response-end-response-close-and-how-customer-feedback-helps-us-improve-msdn-documentation.aspx 분명히 context.Response.Close() 또는 context.Response.End()를 사용해서는 안됩니다.

코드 내가 사용하고 있습니다 :

using System.Web; 

namespace WebFront.Documents 
{ 
    public class PDFDownloader : IHttpHandler 
    { 

     public void ProcessRequest(HttpContext context) 
     { 
      // Makes sure the page does not get cached 
      context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 

      // Retrieves the PDF 
      byte[] PDFContent = BL.PDFGenerator.GetPDF(context.Request.QueryString["DocNumber"]); 

      // Send it back to the client 
      context.Response.ContentType = "application/pdf"; 
      context.Response.BinaryWrite(PDFContent); 
      context.Response.Flush(); 
     } 

     public bool IsReusable 
     { 
      get 
      { 
       return false; 
      } 
     } 
    } 
} 

사람이 문제의 동일한 유형에 직면 했습니까?

+0

가능한 복제본 [IE 8 및 클라이언트 측 캐싱] (http://stackoverflow.com/questions/8348214/ie-8-and-client-side-caching)도 http://stackoverflow.com/을 참조하십시오. 질문/9185678/ie7-8-pdf-file-wont-download-with-http-get – nemesv

답변

2

트릭을했다.

+0

고마워요! 나는 똑같은 문제를 가지고 있었고'Response.ClearHeaders();에 추가했다. 바로 수정했다. –

0

Response.End으로 전화하십시오.

응답을 끝내고 브라우저에 모든 콘텐츠가 수신되었음을 알리십시오. 바른 길에 나를 넣어 주셔서 @nunespascal에

public void ProcessRequest(HttpContext context) 
{ 
    // Makes sure the page does not get cached 
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 

    // Retrieves the PDF 
    byte[] PDFContent = BL.PDFGenerator.GetPDF(context.Request.QueryString["DocNumber"]); 

    // Send it back to the client 
    context.Response.ClearHeaders(); 
    context.Response.ContentType = "application/pdf"; 
    context.Response.BinaryWrite(PDFContent); 
    context.Response.Flush(); 
    context.Response.End(); 
} 

어쨌든 감사 : 콘텐츠 유형을 설정하기 전에 헤더를 삭제

public void ProcessRequest(HttpContext context) 
     { 
      // Makes sure the page does not get cached 
      context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 

      // Retrieves the PDF 
      byte[] PDFContent = BL.PDFGenerator.GetPDF(context.Request.QueryString["DocNumber"]); 

      // Send it back to the client 
      context.Response.ContentType = "application/pdf"; 
      context.Response.BinaryWrite(PDFContent); 
      context.Response.Flush(); 
      context.Response.End(); 
     } 
+0

빠른 답변 주셔서 감사합니다! 나는 여전히 .End()와 .Close()가 절대로 사용되어서는 안된다는 MSDN 블로그에 대해 궁금합니다. – Jaepetto

+0

그 이유는 페이지 내에서 결코 사용하지 않는 것과 같은 것입니다. 왜냐하면'ThreadAbortException'이 발생하고 응답을받지 않기 때문입니다. 이 기능은 이유가 있기 때문에 제공되며 용도가 있습니다. – nunespascal