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
39
votes
3 answers

RoutePrefix vs Route

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…
39
votes
1 answer

Attribute routing with optional parameters in ASP.NET Web API

I'm trying to use Web API 2 attribute routing to set up a custom API. I've got my route working such that my function gets called, but for some reason I need to pass in my first parameter for everything to work properly. The following are the URLs I…
sohum
  • 3,207
  • 2
  • 39
  • 63
39
votes
2 answers

Web API routing with multiple parameters

I'm trying to work out how to do the routing for the following Web API controller: public class MyController : ApiController { // POST api/MyController/GetAllRows/userName/tableName [HttpPost] public List GetAllRows(string…
Mourndark
  • 2,526
  • 5
  • 28
  • 52
36
votes
2 answers

Multiple Routes on a Controller

Was wondering if it was possible to have more than one route pointing to a WebApi controller? For example I will like to have both http://domain/calculate and http://domain/v2/calculate pointing to the same controller function?
Darren
  • 497
  • 1
  • 4
  • 10
33
votes
9 answers

asp.net webapi 2 attribute routing not working

I have visual studio 2012 installed with mvc4 using .net framework 4.5. Now I want to use webapi2 with attribute writing and i want my hlep page show all the endpoints properly. In my solution i added a new mvc4 base emtpy project and using nuget i…
Najam Awan
  • 1,113
  • 3
  • 13
  • 30
27
votes
4 answers

Routing based on query string parameter name

I'm trying to configure routing in my MVC4 WebAPI project. I want to be able to search for products based on their name or their type like so: /api/products?name=WidgetX - returns all products named WidgetX /api/products?type=gadget - returns all…
rickythefox
  • 6,601
  • 6
  • 40
  • 62
26
votes
2 answers

composite key resource REST service

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…
25
votes
2 answers

Manually set operationId to allow multiple operations with the same verb in Swashbuckle

I need to know if it's possible to set up custom operationid, or a naming convention, I mean I know that operation filter can be overwritten the way how operationId is…
25
votes
1 answer

Web API Routes to support both GUID and integer IDs

How can I support GET routes for both GUID and integer? I realize GUIDs are not ideal, but it is what it is for now. I'm wanting to add support for integers to make it easier for users to remember and communicate what should be unique…
gopherr
  • 673
  • 1
  • 8
  • 12
25
votes
1 answer

ASP.NET Web API multiple RoutePrefix

The opensource Attribute Routing allows to have multiple route-prefixes. Why does ASP.NET Web API 2.0 does not allow to have multiple RoutePrefix(). [RoutePrefix("api/v1/{abc}/Entity")] [RoutePrefix("api/v1/{abc}/{xyz?}/Entity")] public class…
25
votes
3 answers

Multiple Controller Types with same Route prefix ASP.NET Web Api

Is it possible to separate GETs and POSTs into separate API Controller types and accessing them using the same Route Prefix? Here are my controllers: [RoutePrefix("api/Books")] public class BooksWriteController : EventStoreApiController { …
24
votes
3 answers

+ (plus) sign in Web API routing

I'm working with an asp.net web api project, and I have to pass an mobile number through a post. But i cannot return a plus sign. my route: config.Routes.MapHttpRoute( name: "SmsRoute", routeTemplate:…
krisal
  • 621
  • 6
  • 19
22
votes
3 answers

How to map WebAPI routes correctly

I'm building an API for a Twitter like site using Web API and have trouble with mapping the routes I have the following actions for the User controller: public User Get(string firstname, string lastname) public User Get(Guid id) public User…
22
votes
3 answers

How can I generate a WebApi2 URL without specifying a Name on the Route attribute with AttributeRouting?

I've configured my ASP.NET MVC5 application to use AttributeRouting for WebApi: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); } } I have an…
crush
  • 16,713
  • 9
  • 59
  • 100
22
votes
3 answers

WebApi: mapping parameter to header value

I've done a few searches but haven't seem to find anything... Using WebApi, I would like to map an input parameter to a header value: e.g. E.g. in controller: public User GetUser(int id){ ... return user; } I want WebApi to map the id…
frigon
  • 4,979
  • 7
  • 32
  • 38
1
2
3
69 70