Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# .Net 6 Can't hit API route

I’m not able to hit my api routes on new project I configured even though everything looks right. Controller looks like

{
    [Route("api/[controller]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMapper _mapper;
        private readonly UserManager<User> _userManager;
        private readonly SignInManager<User> _signInManager;
        private readonly ILogger<AccountController> _logger;

        public AccountController(IMapper mapper, UserManager<User> userManager, SignInManager<User> signInManager, ILogger<AccountController> logger)
        {
            _mapper = mapper;
            _userManager = userManager;
            _signInManager = signInManager;
            _logger = logger;
        }



        [HttpGet("/Test")]
        public String Test()
        {
            var z = 7;
            return "Route Hit";
        }

and I’ve tried various requests such as

https://localhost:5001/api/account/test
https://localhost:5001/api/account/Test
https://localhost:5001/api/Account/test
https://localhost:5001/api/Account/Test
https://localhost:5001/api/AccountController/Test
https://localhost:5001/api/AccountController/test

but all of them return a 404 eerror. Why might that be every thing looks correct from what I see. This is on a project I was converting from MVC app to Web API

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Example pic

>Solution :

By request of the OP.

This should be configurated in route file

But the slash is taken from the root, so you must remove it to made it as relative path.

    [HttpGet("Test")]
    public String Test()
    {
        var z = 7;
        return "Route Hit";
    }

or complete the sequence from the route.

    [HttpGet("/api/account/Test")]
    public String Test()
    {
        var z = 7;
        return "Route Hit";
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading