I wrote this API in .net. I am trying to call this method through Fiddler and getting the below error message:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /api/allItProjectsLists/Index</pre>
</body>
</html>
Not sure what am I doing wrong. Is there any way, I can put a breakpoint inside method Index and find out what is wrong. Below is my API code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectDetails.Models;
using ProjectDetails.Data;
using ProjectDetails.Interfaces;
namespace ProjectDetails.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AllItProjectsListsController : ControllerBase
{
private readonly KPIContext _context;
private readonly IProject objProject;
public AllItProjectsListsController(IProject _objProject)
{
objProject = _objProject;
}
[HttpGet("/Index")]
public IEnumerable<AllItProjectsList> Index()
{
return objProject.GetAllProjectDetails();
}
[HttpPost]
[Route("api/AllItProjectsLists/Create")]
public int Create([FromBody] AllItProjectsList project)
{
return objProject.AddProject(project);
}
[HttpGet]
[Route("api/AllItProjectsLists/Details/{id}")]
public AllItProjectsList Details(int id)
{
return objProject.GetProjectData(id);
}
[HttpPut]
[Route("api/AllItProjectsLists/Edit")]
public int Edit([FromBody]AllItProjectsList project)
{
return objProject.UpdateProject(project);
}
[HttpDelete]
[Route("api/AllItProjectsLists/Delete/{id}")]
public int Delete(int id)
{
return objProject.DeleteProject(id);
}
[HttpGet]
[Route("api/AllItProjectsLists/GetAppDevList")]
public IEnumerable<AppDev> GetAppDev()
{
return objProject.GetAppDevs();
}
any help with the above debugging will be highly appreciated. In Fiddler, I typed the following URL:
https://localhost:44313/api/AllItProjectsLists/Index
Below is the image from Fiddler:
You need to change [HttpGet("/Index")]
to [HttpGet("Index")]
on your action for attribute routing.
[HttpGet("/Index")]
will be executed for a URL as https://localhost:44313/Index
[HttpGet("Index")]
will be executed for a URL as https://localhost:44313/api/AllItProjectsLists/Index
Refer to attribute routing
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments