0

I have a Net Core 2.1 console app that uses Kestrel for hosting/listening with the following endpoint.

 [Route("[controller]")]
    public class NameController 
    {
       [HttpGet]
        public async Task<IActionResult> Get()
        {
            return new OkObjectResult("Response");
        }
    }

When I run it I get the console with the following text...

Now listening on: http://localhost:5000
Now listening on: https://localhost:5001

But when I try to access that Get() method via these URLs I get a 404.

http://localhost:5000/ControllerName
https://localhost:5001/ControllerName

If it's listening I should be able to access the endpoint right?

John
  • 371
  • 2
  • 4
  • 16
  • Not `http://localhost:5000/Name` ? – ProgrammingLlama Jan 16 '20 at 00:00
  • Sorry that is what I was doing. :) – John Jan 16 '20 at 00:01
  • Change your route to controller without square brackets and access http://localhost:port/controller – Jawad Jan 16 '20 at 00:05
  • @Jawad `[controller]` is a [token](https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-3.1#token-replacement-in-route-templates-controller-action-area). Though looking at those docs, I note that OP isn't inheriting from `Controller`, which might make a difference. – ProgrammingLlama Jan 16 '20 at 00:14

0 Answers0