Linked Questions

Popular Questions

ASP.Net route not being hit, returning 404 error on postman?

Asked by At

I have an ASP.NET Web API router that seems to not get hit when I navigate to the proper route.

Here is my Web API controller:

public class AccountController : ControllerBase
    #region Declarations
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly RoleManager<IdentityRole> _roleManager;
    private readonly ApplicationDbContext _context;
    private readonly IHostingEnvironment _hostingEnvironment;

    public AccountController(
        UserManager<ApplicationUser> userManager,
        RoleManager<IdentityRole> roleManager,
        ApplicationDbContext context,
        IHostingEnvironment environment
        _userManager = userManager;
        _roleManager = roleManager;
        _context = context;
        _hostingEnvironment = environment;

    public ActionResult<IEnumerable<string>> Get()
        return new string[] { "Account", "Controller" };

    public async Task<IActionResult> GetToken()
        var client = new DiscoveryClient("http://localhost:15547");
        client.Policy.RequireHttps = false;
        var disco = await client.GetAsync();
        if (disco.IsError)
            return BadRequest(disco.Error);

        TokenClient tokenClient = new TokenClient(disco.TokenEndpoint, "ro.angular", "secret");
        TokenResponse tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync("ahmer", "[email protected]", "api1 openid");

        if (tokenResponse.IsError)
            return BadRequest(tokenResponse.Error);

        //var user = _userManager.FindByNameAsync(model.UserName);

        var result = await _userManager.FindByNameAsync("ahmer");

        return BadRequest("Invalid username or password.");

However, my GET http://localhost:15547/api/account/ route works fine, but when I try to make a POST request http://localhost:15547/api/account/GetToken it is not hit and it shows me 404 message from Postman. What I m doing wrong in my code.

Output 1

enter image description here

Output 2

enter image description here

Related Questions