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
272
votes
18 answers

Multiple actions were found that match the request in Web Api

I keep getting this error when I try to have 2 "Get" methods Multiple actions were found that match the request: webapi I been looking around at the other similar questions about this on stack but I don't get it. I have 2 different names and…
chobo2
  • 83,322
  • 195
  • 530
  • 832
223
votes
43 answers

Post parameter is always null

Since upgrading to RC for WebAPI I'm having some real odd issue when calling POST on my WebAPI. I've even gone back to the basic version generated on new project. So: public void Post(string value) { } and calling from Fiddler: Header: User-Agent:…
ianrathbone
  • 2,334
  • 2
  • 15
  • 16
179
votes
3 answers

Can anyone explain CreatedAtRoute() to me?

From the template for Web API 2, a post method is always like this: [ResponseType(typeof(MyDTO))] public IHttpActionResult PostmyObject(MyDTO myObject) { ... return CreatedAtRoute("DefaultApi", new { id = myObject.Id }, myObject); } I don't…
martial
  • 3,773
  • 8
  • 33
  • 43
134
votes
12 answers

Multiple HttpPost method in Web API controller

I am starting to use MVC4 Web API project, I have controller with multiple HttpPost methods. The Controller looks like the following: Controller public class VTRoutingController : ApiController { [HttpPost] public MyResult…
Habib
  • 219,104
  • 29
  • 407
  • 436
116
votes
8 answers

Custom method names in ASP.NET Web API

I'm converting from the WCF Web API to the new ASP.NET MVC 4 Web API. I have a UsersController, and I want to have a method named Authenticate. I see examples of how to do GetAll, GetOne, Post, and Delete, however what if I want to add extra methods…
Justin
  • 17,670
  • 38
  • 132
  • 201
116
votes
4 answers

Optional Parameters in Web Api Attribute Routing

I want to handle POST of the following API-Call: /v1/location/deviceid/appid Additional Parameter are coming from the Post-Body. This all works fine for me. Now I wnat to extend my code by allowing "deviceid" and/or "appid" and/or BodyData to be…
Oliver Apel
  • 1,808
  • 3
  • 19
  • 31
87
votes
17 answers

FromBody string parameter is giving null

This is probably something very basic, but I am having trouble figuring out where I am going wrong. I am trying to grab a string from the body of a POST, but "jsonString" only shows as null. I also want to avoid using a model, but maybe this isn't…
68
votes
8 answers

Query string not working while using attribute routing

I'm using System.Web.Http.RouteAttribute and System.Web.Http.RoutePrefixAttribute to enable cleaner URLs for my Web API 2 application. For most of my requests, I can use routing (eg. Controller/param1/param2) or I can use query strings (eg.…
66
votes
3 answers

Attribute routing and inheritance

I am playing around with the idea of having a base controller that uses a generic repository to provide the basic CRUD methods for my API controllers so that I don't have to duplicate the same basic code in each new controller. But am running into…
Jeff Treuting
  • 13,910
  • 8
  • 36
  • 47
64
votes
10 answers

Routing with multiple Get methods in ASP.NET Web API

I am using Web Api with ASP.NET MVC, and I am very new to it. I have gone through some demo on asp.net website and I am trying to do the following. I have 4 get methods, with the following signatures public List Get() { // gets all…
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
58
votes
16 answers

No type was found that matches the controller named 'User'

I'm trying to navigate to a page which its URL is in the following format: localhost:xxxxx/User/{id}/VerifyEmail?secretKey=xxxxxxxxxxxxxxx I've added a new route in the RouteConfig.cs file and so my RouteConfig.cs looks like this: public class…
53
votes
4 answers

Route parameter with slash "/" in URL

I know you can apply a wildcard in the route attribute to allow / such as date input for example: [Route("orders/{*orderdate}")] The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the…
bet
  • 962
  • 1
  • 9
  • 22
47
votes
1 answer

Web API routing constraint Patch missing in HttpMethod

I am building some restful api using .net Web API V1. We are trying to define some routing for the web api. I am having some issue in defining the route for 'Put' and 'patch'. They have the same URL and the only different is in the HttpMethod. In…
45
votes
4 answers

CreatedAtRoute routing to different controller

I'm creating a new webapi using attribute routing to create a nested route as so: // PUT: api/Channels/5/Messages [ResponseType(typeof(void))] [Route("api/channels/{id}/messages")] public async Task
DanH
  • 3,772
  • 2
  • 27
  • 31
41
votes
9 answers

Not supported by Swagger 2.0: Multiple operations with path

I have integrated swagger in WebApi 2 application. It works fine when application has single controller. When I added second controller in the application. I got following error : An error has occurred.","ExceptionMessage":"Not supported by…
1
2 3
69 70