Coding⏱️ 1 min read📅 2026-05-31

How to Fix: How do I return NotFound() IHttpActionResult with an error message or exception?

Return NotFound() IHttpActionResult with custom error message or exception in ASP.NET WebAPI.

Quick Answer: Use the NotFound() overload that takes a string parameter to return a custom error message, or create a custom IHttpActionResult class to include additional information.

To return a NotFound IHttpActionResult with an error message or exception, you can use the NotFound() method's overload that accepts a string parameter. This allows you to pass a custom error message.

💡 Using the NotFound() Method

  • Use the NotFound() method with a string parameter, like this: return NotFound($

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database