0

저는 응용 프로그램을 제작 중이며 코딩 도중 내용이없는 500 내부 서버 오류가 발생하는 경우가 있습니다. 내가 로컬이 때Azure 서비스 응용 프로그램 [Mobileservice] - 사용자 정의 오류 응답

[HttpGet] 
    [Route("TryCatch")] 
    public IHttpActionResult TestCatch() 
    { 
     try 
     { 
      object obj = null; 
      int i = (int) obj; 
      return Ok(); 
     } 
     catch (Exception e) 
     { 
      return InternalServerError(e); 
     } 
    } 

가, 내가달라고 오류에 관한 정보를 수신 할 : 나는 다음과 같이 컨트롤러에서 오류 응답을 테스트하기 위해 코드를 썼다. 제작 과정에서 보았을 때 나는 (우편 배달부에서) { "message": "오류가 발생했습니다." } 및 상태 코드.

저는 주위를 둘러 보았고 문제에 대한 해결책이라고 생각했던 것을 발견했습니다 : Internal Server Error - Azure App Service Custom Controller하지만 그렇지 않았습니다.

그리고 <httpErrors errorMode="Custom" defaultResponseMode="passThrough"> 또는 <customErrors mode="On"/> 또는 web.config의 내용을 추가해도 도움이되지 않습니다.

도움을 주시면 감사하겠습니다.

답변

0

사용자 지정 오류 모드를 켜기 대신 끄기로 변경하십시오.

<customErrors mode="Off"/> 

그리고 IncludeErrorDetailPolicy에게 재산을 변경하려면 항상 WebApiConfig.cs 파일 (푸른 모바일 서비스) 또는 Startup.cs 파일 (푸른 모바일 앱)이다.

config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; 

그런 다음 exceptionMessage 속성에서 세부 예외 메시지를 가져올 수 있습니다.

{"message":"An error has occurred.","exceptionMessage":"Object reference not set to an instance of an object.","exceptionType":"System.NullReferenceException","stackTrace":""} 
+0

고맙습니다! 'config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;'그 부분이 내 문제를 해결했습니다! –