简体   繁体   中英

The API is throwing wrong response code 500 internal error instead 204

We observed a sudden change in the behavior of API response codes. In my local system it's retuning 204 - No Content fine . But, after deploying into Azure App Service (running ASP.NET 4.8 stack), it's returning 500 internal error ( requested from Post man tool as shown in the attached pictures)

Please Note: It was working earlier with the same code and in the App Service

We can reproduce the issue with simple code below in Web API (4.6.1 FW I am using)

Suspecting its due to some Pass level changes. Please share if any one facing similar issue or any clues how to fix this issue.

Its simple to reproduce the issue with below line of code Web API and triggering the request Local vs App Service (will be greatfull if any one can re-produce to understand the real issue I am trying to convey. Thanks.

Code Snippet在此处输入图像描述

Local: no Issue在此处输入图像描述

Issue after deploying into App Service在此处输入图像描述

The Root of this issue: After lot of analysis and discussions with Microsoft Teams, understood that there is recent introduction of higher security compliance in front of Azure Front End. This change enforcing that content should not be returned with HTTP 204. ( Reference source: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html )

Why it was working earlier: Because It was compatible and no issues even we return Content in the 204 response before.

Mitigation

  • Approach 1: Avoid returning content with 204 response.
  • Approach 2: Disable security compliance as Quick fix and slowly update your code not to return content with 204 response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM