0

So i have this ASP.NET Core on my local machine, i have installed the prerequisites and after running the application locally, the response was correct from the web browset that it was not found.

Okay, i am trying to invoked this API via Postman and i couldnt determine why i cant access it though i already checked the routings.

Below is the sample template

[HttpGet]
    [Route("Details")]
    public async Task<IActionResult> GetDetails(string value = null)
    {
        var response = new ListModelResponse<SomeModel>() as IListModelResponse<SomeModel>;

        try
        {
            response.Model = await GetDetailsRepository
                    .GetDetailsSS(value)
                    .Select(item => item.ToViewModel())      
                    .OrderBy(item => item.Name)
                    .ToListAsync();
        }
        catch (Exception ex)
        {
            response.DidError = true;
            response.ErrorMessage = ex.Message;
        }

        return response.ToHttpResponse();
    }

And in application insights of visual studio, i can see that it is invoking the API but it seems it can't get through. Check this insights snippet

Other API's are working fine, it seems that i am missed something that i can't figure out right now.

For the routing i have this.

[Route("api/[controller]")]

I have also checked the Token and as i parsed it, i am getting the required info to access this API.

Thanks Lads!

5
  • Why do you miss the controller name in your url? Commented Feb 5, 2020 at 2:39
  • @Rena, what do you mean i miss the controller name in the URL? i have the controller name 'Details' that's what im using. Can you please elaborate? Thanks Commented Feb 5, 2020 at 5:51
  • Hi @Rgnr, If your controller name is DetailsController.You need to request the url like:api/Details/Details?value=CAT.Because you add the [Route("Details")] on your method.The route attribute does not mean your controller name. Commented Feb 5, 2020 at 6:02
  • @Rgnr Did any of these answers resolve your issue? Commented Feb 5, 2020 at 12:20
  • Sorry guys, This is my real mistake, i was thinking that the method is the registered route in my application. You are all correct, Thanks all! I missed that controller in postman *slap Commented Feb 5, 2020 at 13:12

2 Answers 2

1

It doesn't seem that you have the name of the controller in the request url.

api/[controller]/Details?value=CAT...

Sign up to request clarification or add additional context in comments.

Comments

1

This error is due to the incorrect url present in the request. The correct URL has to be https://localhost:44309/api/your-controller-name/Details?value=CAT

ie. If the Controller name is ProductsController, then the URL has to be https://localhost:44309/api/Products/Details?value=CAT.

[Route("api/[controller]")]
public class ProductsController : Controller
{
   [HttpPost("Details")]     
    public async Task<IActionResult> GetDetails(string value = null)
    {
        ...
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.