I have an ASP.Net Core MVC app with a Web API controller, I believe i provided the right routes and everything but i still get a 404 error when calling the any API of the controller in Postman
here is how the controller looks:
[Route("api/[controller]")]
[ApiController]
public class PetsController : Controller
{
private readonly IPetService _petService;
public PetsController(IPetService _petService)
{
this._petService = _petService;
}
[HttpPost("Activation")]
public async Task<IActionResult> Activation(Guid id)
{
var serviceResult = await _petService.DeletePet(id);
return Ok(serviceResult);
}
[HttpGet("GetPet/{id}")]
public async Task<IActionResult> GetPet(Guid id)
{
var serviceResult = await _petService.GetPetDetails(id);
return Ok(serviceResult);
}
[HttpGet("GetPets/{pageSize}/{pageIndex}/{keyWord}")]
public async Task<IActionResult> GetPets(int pageSize, int pageIndex, string keyWord)
{
var serviceResult = await _petService.GetPets(pageSize, pageIndex, keyWord);
return Ok(serviceResult);
}
[HttpPost("SavePet")]
public async Task<IActionResult> SavePet(PetDTO pet)
{
var serviceResult = (Object)null;
if (!pet.Id.HasValue)
serviceResult = await _petService.CreatePet(pet);
else
serviceResult = await _petService.EditPet(pet);
return Ok(serviceResult);
}
[HttpGet("GetPetDues/{id}")]
public async Task<IActionResult> GetPetDues(Guid id)
{
var serviceResult = await _petService.GetPetDues(id);
return Ok(serviceResult);
}
[HttpGet("GetPetAppointments/{id}")]
public async Task<IActionResult> GetPetAppointments(Guid id)
{
var serviceResult = await _petService.GetPetAppointments(id);
return Ok(serviceResult);
}
[HttpGet("GetPetDiseases/{petId}")]
public async Task<IActionResult> GetPetDiseases(Guid petId)
{
var serviceResult = await _petService.GetPetDiseases(petId);
return Ok(serviceResult);
}
}
Launch settings:
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50521",
"sslPort": 44310
}
and this is an examply on how i call an API in Postman: http://localhost:50521/api/pets/GetPets/10/0/
I believe I should get a 200 OK but still im getting a 404 error! How can i fix this??