---
title: "What is the HTTP status code when a resource is not found? How to handle it?"  
description: "What is the HTTP status code when a resource is not found? How to handle it?"  
author: "Sandra Emily"  
published: 2023-08-28  
updated: 2023-08-29  
canonical: https://www.mindstick.com/forum/159703/what-is-the-http-status-code-when-a-resource-is-not-found-how-to-handle-it  
category: ".net core"  
tags: ["asp.net core", ".net core", "http 404", ".net core api"]  
reading_time: 2 minutes  

---

# What is the HTTP status code when a resource is not found? How to handle it?

What is the [HTTP status](https://www.mindstick.com/forum/160304/importance-of-http-status-codes-in-responses-to-httppost-methods-requests-in-dot-net-core-api) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) when a [resource](https://www.mindstick.com/blog/43433/top-best-resources-for-women-about-beauty-and-health) is not found? How to [handle](https://www.mindstick.com/articles/311004/suede-skillet-handle-cover) it?

## Replies

### Reply by Aryan Kumar

The [HTTP](https://www.mindstick.com/blog/217/http-endpoints-in-sql-server-2005-2008) [status](https://www.mindstick.com/articles/157184/check-lic-policy-status-online-by-policy-number) code when a resource is not found is 404 Not Found. This status code indicates that the server cannot find the requested resource. The resource may have been deleted, moved, or never existed in the first place.

To handle a 404 Not Found error, you can return a response with the following information:

- The HTTP status code 404 Not Found.
- A brief message indicating that the resource was not found.
- A link to the home page or other relevant page.

The following code shows how to handle a 404 Not Found error in a .NET Core API:

C#

```plaintext
[ApiController]
[Route("[controller]")]
public class ProductController : ControllerBase {

  [HttpGet("{id}")]
  public IActionResult Get(int id) {
    // Get the product data from the database.
    // ...

    // If the product data is not found, return a 404 Not Found response.
    if (!productRepository.Exists(id)) {
      return NotFound();
    }

    // Return the product data.
    return Ok(product);
  }
}
```

In this code, the `Get()` action method first tries to get the product data from the database. If the product data is not found, the method returns a 404 Not Found response.

Here are some additional tips for handling 404 Not Found errors:

- Use a consistent error message across your API. This will help users understand what went wrong and how to fix it.
- Use a descriptive error code. This will help users troubleshoot the error.
- Provide a link to the home page or other relevant page. This will help users get back to where they were before the error occurred.


---

Original Source: https://www.mindstick.com/forum/159703/what-is-the-http-status-code-when-a-resource-is-not-found-how-to-handle-it

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
