Home > Net >  HttpGet route not found
HttpGet route not found

Time:05-21

I have built a controller. For some unknown reason the end point is not reached. Unfortunately I do not understand why.

[Route("api/realestates")]
[ApiController]
public class RealEstateController : CustomControllerBase<RealEstateController>
{
    [HttpGet]   // not reached
    public async Task<IResult<List<RealEstateListDTO>>> GetAll()
    {
        //[...]
    }
}

If i change the route from controller to api/realestate or from Get-method to [HttpGet("all")] it works. In the CustomControllerBase are no routes defined.

CodePudding user response:

check your endpoint in postman or browser and check your startup has something like this

services.AddControllersWithViews 

or

 services.AddControllers

and your customecontroller must inherits ControllerBase

CodePudding user response:

You’re calling ‘api/realestate’

But in the attribute you’ve defined ‘api/realestates’

So try with the ‘s’ at the end

If you want the route to match the controller name (minus “Controller”). You should change your route attribute to -

[Route("api/[controller]")]
  • Related