2013-11-22 2 views
0

내 데이터베이스에 저장된 데이터에서 PDF 파일을 표시하려고합니다. 그것은 byte[] 형식입니다. 다음 코드는 성공적으로 새로운 IE 탭에 PDF 파일을 표시하지만 try catch 문에서 예외 오류가 발생합니다.C에서 바이트 []의 PDF 표시

내 코드 샘플 :

try { 

    byte[] byteOutput = myObject.ContractBytes; 
    Response.ClearHeaders(); 
    HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=file.pdf"); 
    HttpContext.Current.Response.ContentType = "application/pdf"; 
    Response.BinaryWrite(byteOutput); 
    Response.Flush(); 
    Response.End(); 
} 
catch (Exception ex) 
{ 
    RecordError(ex.Message, ex); 
} 

내 예외 오류가 :

Thread was being aborted. 
at System.Threading.Thread.AbortInternal() 
at System.Threading.Thread.Abort(Object stateInfo) 
at System.Web.HttpResponse.AbortCurrentThread() 
at System.Web.HttpResponse.End() 
at GetForm.FromDatabase() in c:\\SRC\\GetPDF.aspx.cs:line 340 
at GetForm.Page_Load(Object sender, EventArgs e) in c:\\SRC\\MyPage.aspx.cs:line 106 

어떤 도움을 주시면 감사하겠습니다!

고맙습니다.

+1

'this.Context.ApplicationInstance.CompleteRequest()'대신''으로 Response.End()의 호출 시도 - 이것은'ThreadAbortException'을 던져 응답을 종료하지 않습니다. –

답변

1

read the documentation?

This method is provided only for compatibility with ASP—that is, for compatibility with COM-based Web-programming technology that preceded ASP.NET. If you want to jump ahead to the EndRequest event and send a response to the client, it is usually preferable to call CompleteRequest instead.

To mimic the behavior of the End method in ASP, this method tries to raise a [ThreadAbortException] exception. If this attempt is successful, the calling thread will be aborted, which is detrimental to your site's performance. In that case, no code after the call to the End method is executed.

If the End method is not able to raise a [ThreadAbortException], it instead flushes the response bytes to the client. It does this synchronously, which can also be detrimental to your site's performance.

In either case (whether or not a [ThreadAbortException] exception is successfully raised), the response pipeline jumps ahead to the EndRequest event.

The CompleteRequest method does not raise an exception, and code after the call to the CompleteRequest method might be executed. If your intention is to avoid execution of subsequent code, and if the performance penalty of End is acceptable, you can call End instead of CompleteRequest .

+0

이 코드는 제가 직책을 맡기 전에 작성되었습니다. 제공해 주신 답변에 감사드립니다. – Turp

3

다음과 같은 진술이 그 오류를 생성하고 있다고 생각합니다.

Response.End(); 

왜 필요한가요? 이 호출없이 코드를 사용해 보셨습니까?