소프트웨어/C# & ASP.NET

Response.End, Response.Redirect 또는 Server.Transfer를 사용하면 ThreadAbortException이 발생한다

falconer 2009. 11. 5. 10:35

HttpContext.Current.ApplicationInstance.CompleteRequest()

  catch (System.Threading.ThreadAbortException exf)
  {
   // The normal treatment process(ThreadAbortException)
  }  
  catch (Exception ex)
  {
   // log..
  }




현상
Response.End, Response.Redirect 또는 Server.Transfer 메서드를 사용하면 ThreadAbortExceptio...

Response.End, Response.Redirect 또는 Server.Transfer 메서드를 사용하면 ThreadAbortException 예외가 발생합니다. try-catch 문을 사용하면 이 예외를 catch할 수 있습니다.

원인
Response.End 메서드는 페이지 실행을 종료시키고 해당 응용 프로그램 이벤트 파이프라인의 Application_EndRequest 이벤트...

Response.End 메서드는 페이지 실행을 종료시키고 해당 응용 프로그램 이벤트 파이프라인의 Application_EndRequest 이벤트로 실행을 이동합니다. Response.End 다음에 오는 코드 줄들은 실행되지 않습니다.

Response.Redirect 메서드와 Server.Transfer 메서드가 모두 내부적으로 Response.End를 호출하기 때문에 이러한 문제가 발생합니다.

해결 방법
이 문제를 해결하려면 다음 방법 중 하나를 사용하십시오. Response.End의 경우 Response.End 대신 HttpContext.Cur...

이 문제를 해결하려면 다음 방법 중 하나를 사용하십시오.
  • Response.End의 경우 Response.End 대신 HttpContext.Current.ApplicationInstance.CompleteRequest 메서드를 호출하여 Application_EndRequest 이벤트에 대한 코드 실행을 무시합니다.
  • Response.Redirect의 경우 endResponse 매개 변수에 대해 false를 전달하여 Response.End를 내부적으로 호출하지 않도록 하는 Response.Redirect(String url, bool endResponse) 오버로드를 사용합니다. 예는 다음과 같습니다.
      Response.Redirect ("nextpage.aspx", false);
    						
    이 해결 방법을 사용하면 Response.Redirect 다음에 오는 코드가 실행됩니다.
  • Server.Transfer의 경우 Server.Execute 메서드를 대신 사용합니다.




참고 :
http://support.microsoft.com/kb/312629/ko
http://www.kbalertz.com/Feedback.aspx?kbNumber=312629

'소프트웨어 > C# & ASP.NET' 카테고리의 다른 글

dotTrace - Performance profiling  (0) 2009.11.11
SlimTune  (0) 2009.11.11
ASP.NET 2.0에서 중첩 Repeater 사용하기  (0) 2009.11.03
C# 초보자분들을 위한 기초강좌  (0) 2009.11.03
DateTime형 유용한 유틸리티  (0) 2009.11.03