2014-02-15 6 views
1

: 내가 사용하는 말되었다차이 HttpContext.Current.ApplicationInstance.Context의 차이점은 무엇

HttpContext.Current 

HttpContext.Current.ApplicationInstance.Context 

:

Dim context As HttpContext = HttpContext.Current.ApplicationInstance.Context 
If Not IsNothing(context) Then 
    'do stuff with context 
End If 

하지만 Application_EndRe에서 ApplicationInstance.Context에 액세스하려고하면 Null 참조 예외가 발생합니다. 퀘스트 이벤트.

어느 것을 사용해야합니까?

+0

첫 번째 것. – AgentFire

답변

0

속성은 모두 요청의 현재 컨텍스트를 반환합니다. HttpContext.Current이 더 짧기 때문에 이것을 사용해야합니다. 또한 null/Nothing을 검사 할 때 발생하는 오류는 분명합니다.

HttpContext.Current.ApplicationInstance.Context이 null/Nothing 일 경우, HttpContext.Current은 null/Nothing입니다. 따라서 null/Nothing에 대한 컨텍스트를 확인하는 유일한 작업 방법은 다음과 같습니다.

If HttpContext.Current IsNot Nothing Then 
    ' ... 
End If 
관련 문제