Questions tagged [asp.net-web-api-routing]

Questions about routing within ASP.NET Web API framework

The ASP.NET Web API Routing module is responsible for mapping incoming HTTP requests to particular Web.Api controller actions, thereby describing REST endpoints.

Learn more about ASP.NET Web.Api Routing on MSDN

1046 questions
20
votes
4 answers

Web API route to action name

I need a controller to return JSON to be consumed by JavaScript so I inherited from the ApiController class but it isn't behaving as I expected. The Apress book Pro ASP.NET MVC 4 and most of the online examples I've found give examples like: public…
Dave
  • 1,484
  • 3
  • 14
  • 17
19
votes
3 answers

Ambiguous Controller Names with Routing attributes: controllers with same name and different namespace for versioning

I am trying to add API versioning and my plan is to create a controller for each version in different namespace. My project structure looks like this (note: no separate area for each version) Controllers | |---Version0 | | | |-----…
19
votes
3 answers

Pass decimal as value in WebAPI 2 URL

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…
samneric
  • 3,038
  • 2
  • 28
  • 31
19
votes
3 answers

The inner handler has not been assigned using WebApi Delegating handler

I have got a problem with WebApi throwing an exception here in my code: public class WebApiAuthenticationHandler : DelegatingHandler { private const string AuthToken = "AUTH-TOKEN"; protected override Task
jaffa
  • 26,770
  • 50
  • 178
  • 289
18
votes
3 answers

Web Api Controller in other project, route attribute not working

I have a solution with two projects. One Web Api bootstap project and the other is a class library. The class library contains a ApiController with attribute routing. I add a reference from web api project to the class library and expect this to…
17
votes
2 answers

Web Api HTTPPost not accepting int

I am trying to just pass in body a int and it does not work Why do I need to create a class with a property of type int ? (then it works) WORKS [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult…
user6321478
17
votes
2 answers

Route all Web API requests to one controller method

Is it possible to customize ASP.NET Web API's routing mechanism to route all requests to the API to one controller method? If a request comes in to www.mysite.com/api/products/ or www.mysite.com/api/otherResource/7 All would be routed to my…
msk
  • 1,052
  • 3
  • 15
  • 31
17
votes
1 answer

Replacement for Url.Link when using attribute routing

I have upgraded my project from webapi to webapi2 and are now using attribute routing. I had a method where I used Url helper to get url. Which is the best way to replace Url helper (because this is not working for attributes). My example code of…
17
votes
1 answer

Enabling CORS with WebAPI PUT / POST requests?

I've tried following this post but I'm still not quite there: CORS support for PUT and DELETE with ASP.NET Web API In my web.config I have the following:
SB2055
  • 12,272
  • 32
  • 97
  • 202
16
votes
4 answers

ASP.NET Core Web API: Routing by method name?

I remember from ASP.NET Web API that it's sufficient to prefix Web API REST method names with HTTP commands (e.g. GetList() => HTTP GET, Delete() => HTTP DELETE) to have incoming calls appropriately routed. I also remember that in ASP.NET Web API…
AxD
  • 2,714
  • 3
  • 31
  • 53
16
votes
1 answer

Different RoutePrefix, same controller name

I'm having a problem with splitting my web-api application into different areas (not mvc areas), using namespaces and RoutePrefix The application is hosted using Owin Self Host, and in my Startup class I have the following. HttpConfiguration config…
16
votes
4 answers

Asp.Net MVC4 + Web API Controller Delete request >> 404 error

I have a VS2012 MVC4 solution where I test Web API Controllers. I successfully tested the GET, POST, PUT but the DELETE still got me an http 404 error. When I set a breakpoint in my 'DeleteMovie' action in my api controller, the breakpoint is never…
Bronzato
  • 9,438
  • 29
  • 120
  • 212
16
votes
1 answer

Web api interface works locally but not on Azure

My case is very similar to this question, but since he did not get an answer I thought I'd throw some more input. Everything works fine locally (on the VS embedded server). When I deploy to Azure, I get a 404 error accompanied by "No type was found…
alexbilo
  • 163
  • 1
  • 5
15
votes
1 answer

When and how to use [ResponseType(typeof(...))] correctly?

I am working on a project and I have a basic controller with Get(int id), GetElements(), UpdateElement(int id, Element element), AddElement(Element element) and DeleteElement(int id). Every method use [Route] and [Get]... annotations and returns an…
Chris
  • 6,105
  • 6
  • 38
  • 55
15
votes
2 answers

Is there a default verb applied to a Web API ApiController method?

I've been looking at the code (in https://github.com/patelsan/WebAPIAuthentication) from this article: http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API. It's pretty good and seems to work fine. There are…
djikay
  • 10,450
  • 8
  • 41
  • 52
1 2
3
69 70