asp.net-web-api-routing

ASP.NET CORE Web API - delete action not firing (404 not found)

北城以北 提交于 2021-02-07 14:20:31
问题 I have a simply controller to CRUD operations. All actions works expect the last action named Delete which is HTTP DELETE action. When I try call delete action with example url: http://localhost/api/groups/1/attendances/10 then application returns 404 Not Found and action is not firing. In my other controllers delete action works correctly. One difference is that in others controllers I have one route attribute on controller instead of on each action. This is a problem? public class

Pass decimal as value in WebAPI 2 URL

时间秒杀一切 提交于 2021-02-07 04:57:17
问题 I am creating a Web Api (v2.0) Method that needs to take in a decimal value as its parameter. I am getting a 404 not found error if I use the following URL: http://localhost:4627/api/Product/Eligibility/10.5 But it works if I use the following URL against an Int parameter: Http://localhost:4627/api/Product/Eligibility/10 These are the two corresponding Methods in the api: // GET api/Product/Eligibility/10.0 [Route("api/Product/Eligibility/{amount:decimal}")] public decimal GetEligibiilty

ASP.NET Core Web API runs locally but not on Azure app service

北城余情 提交于 2021-01-05 12:00:20
问题 I have been following this link exactly (https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&tabs=visual-studio) to create my web api. **Locally, it is working fine. Tested the links and it returned JSON data However, once I deploy my web api up to azure app service, all my api links have been returning me error 404. Is there anything that I might have missed out for routing? In my controller I have added this to my head. [Route("api/xxx")] [ApiController]

Core API Controller to catch all unknown routes

蹲街弑〆低调 提交于 2020-08-26 05:47:43
问题 I have a Core 2.2 API with a bunch of existing controllers. What i am now trying to do is add a new controller that acts similar to a catchall route, but only for that controller (and doesn't disturb the routes of the existing controllers) . In my existing controller i am defining the routes as controller attributes [Route("api/[controller]")] [ApiController] public class SandboxController : ControllerBase { [HttpGet("Hello")] public IEnumerable<string> Hello() { return new string[] { "Hello

composite key resource REST service

心不动则不痛 提交于 2020-06-24 07:06:12
问题 I've come across a problem at work where I can't find information on the usual standard or practice for performing CRUD operations in a RESTful web service against a resource whose primary key is a composite of other resource ids. We are using MVC WebApi to create the controllers. For example, we have three tables: Product : PK=ProductId Part : PK=PartId ProductPartAssoc : PK=(ProductId, PartId) A product can have many parts and a part can be a component of many products. The association

RoutePrefix vs Route

♀尐吖头ヾ 提交于 2020-05-09 19:28:25
问题 I understand that RoutePrefix doesn't add a route to the routing table by itself. On your actions you need to have a Route attribute declared. I am having a hard time finding an authoritative blog/msdn page/ something that states why by defalut RoutePrefix doesn't add a route to the routing table. Does anyone have an authoritative post that does contain this to be the case, and if so will you let me know whom it is. Thank you very much. Edit To Clarify my question DOESN'T WORK [RoutePrefix(

RoutePrefix vs Route

梦想与她 提交于 2020-05-09 19:28:14
问题 I understand that RoutePrefix doesn't add a route to the routing table by itself. On your actions you need to have a Route attribute declared. I am having a hard time finding an authoritative blog/msdn page/ something that states why by defalut RoutePrefix doesn't add a route to the routing table. Does anyone have an authoritative post that does contain this to be the case, and if so will you let me know whom it is. Thank you very much. Edit To Clarify my question DOESN'T WORK [RoutePrefix(

Web Api Routing : Multiple controller types were found that match the URL

社会主义新天地 提交于 2020-04-30 16:35:49
问题 I'm getting,"Multiple controller types were found that match the URL", Error while performing postman operation for the below API Calls. Can someone help me figuring out the attribute mapping for the same. What I think is resolver considering the "respond" as the name of the Book. Thanks In Advance Code Snippet : public class BookApiController : ApiController { [HttpGet] [Route("api/v1/books/{bookName}")] public async Task<HttpResponseMessage> Get(string bookName){ /* Code Here */ } } public

Web Api Routing : Multiple controller types were found that match the URL

北城余情 提交于 2020-04-30 16:33:12
问题 I'm getting,"Multiple controller types were found that match the URL", Error while performing postman operation for the below API Calls. Can someone help me figuring out the attribute mapping for the same. What I think is resolver considering the "respond" as the name of the Book. Thanks In Advance Code Snippet : public class BookApiController : ApiController { [HttpGet] [Route("api/v1/books/{bookName}")] public async Task<HttpResponseMessage> Get(string bookName){ /* Code Here */ } } public

How to overload controller methods with same number of arguments in ASP.NET Core Web API?

断了今生、忘了曾经 提交于 2020-04-13 17:42:23
问题 I'm migrating a full .NET Framework Web API 2 REST project over to ASP.NET Core 2.2 and getting a bit lost in the routing. In Web API 2 I was able to overload routes with the same number of parameters based on the parameter type, e.g. I could have Customer.Get(int ContactId) and Customer.Get(DateTime includeCustomersCreatedSince) and incoming requests would be routed accordingly. I haven't been able to achieve the same thing in .NET Core, I either get a 405 error or a 404 and this error