Error messages returned from Web API method are omitted in non-dev environment

后端 未结 5 2085
臣服心动
臣服心动 2020-12-29 22:21

I have a Web API controller POST method that behaves fine locally and on the testing server. If everything goes well it returns:

new HttpResponseMessage( Htt         


        
5条回答
  •  执念已碎
    2020-12-29 22:46

    Had the same issue. It's indeed because of the custom errors setting.

    In a real world scenario, you would definitely want to use a custom error page in your application, but in order for custom exception messages to work in the WebAPI you need to disable the custom errors page.

    How to fix this? Luckily, you can use the element in your web.config to solve this.

    Solution:

      
      
        
      
    
      
      
         
            
         
      
    

    I use this method in my own app, works well.

提交回复
热议问题