Error Message:
Action 'SampleCusAppAPI.Controllers.CustomerController.GetCustomer (SampleCusAppAPI)' does not have an attribute route. Action methods on controllers annotated with ApiControllerAttribute must be attribute routed.
Code: StartUp.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // Error Occured in this line.
});
}
Web Api code: CustomerController
namespace SampleCusAppAPI.Controllers
{
[ApiController]
//[System.Web.Http.Route("api/[controller]")]
public class CustomerController : ControllerBase
{
SampleTestingDBContext objSampleTestingDBContext = new SampleTestingDBContext();
[System.Web.Http.Route("api/Customer/GetCustomer")]
[System.Web.Http.HttpGet]
public IQueryable<Customer> GetCustomer()
{
return objSampleTestingDBContext.Customers.OrderByDescending(x => x.CustomerId);
}
}
}
GetCustomer(SampleCusAppAPI), where is that method? it should be decorated with route attributeGetCustomer(), not forGetCustomer(SampleCusAppAPI), so that's why I asked where that method is.