'API does not hit the controller in production mode
I follow the clean architecture project in .net 6.0
this is ApiControllerBase
[ApiController]
[Route("api/[controller]")]
public abstract class ApiControllerBase : ControllerBase
{
private ISender _mediator = null!;
protected ISender Mediator => _mediator ??= HttpContext.RequestServices.GetRequiredService<ISender>();
}
In my todo Controller, I had the following endpoint
[Route("api/public/todo")]
[AllowAnonymous]
public class PublicTodoController : ApiControllerBase
{
[HttpGet("all")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> All()
{
var result = await Mediator.Send(new GetAllTodoQuery());
return Ok(result);
}
}
when I run production locally it runs but when I sent the request to the above endpoint it throw the following information
Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:5000/api/public/todo/all - -
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'TT.WebApi.Controllers.Public.PublicTodoController.All (TT.WebApi)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "All", controller = "PublicTodoController"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] All() on controller TT.WebApi.Controllers.Public.PublicTodoController (TT.WebApi).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ProblemDetails'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action TT.WebApi.Controllers.Public.PublicTodoController.All (TT.WebApi) in 104.4992ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'TT.WebApi.Controllers.Public.PublicTodoController.All (TT.WebApi)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 GET http://localhost:5000/api/public/todo/all - - - 500 132 application/problem+json;+charset=utf-8 194.1319ms
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
