Questions tagged [attributerouting]

Define your routes using attributes on action methods in ASP.NET MVC and Web API.

NOTE: Attribute Routing support is currently built into Web API. You can read more information about it here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

371 questions
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.…
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
49
votes
6 answers

MVC Attribute Routing Not Working

I'm relatively new to the MVC framework but I do have a functioning Web Project with an API controller that utilizes AttributeRouting (NuGet package) - however, I'm starting another project and it just does not want to follow the routes I put in…
Teagan42
  • 608
  • 1
  • 6
  • 10
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
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
37
votes
4 answers

MapMvcAttributeRoutes: This method cannot be called during the application's pre-start initialization phase

I have a very simple test in a test project in a solution using ASP MVC V5 and attribute routing. Attribute routing and the MapMvcAttributeRoutes method are part of ASP MVC 5. [Test] public void HasRoutesInTable() { var routes = new…
Anthony
  • 5,176
  • 6
  • 65
  • 87
27
votes
2 answers

Using ApiControllerAttribute without using RouteAttribute

In ASP.NET Core (v 2.1.5) you can create controllers without having them inherit from Controller class (as you know). And if you do, you have to use RouteAttribute to define your routes. But, I'm interested if we can use implicit routing (and not…
amiry jd
  • 27,021
  • 30
  • 116
  • 215
27
votes
2 answers

ASP.NET Help Pages default home page?

I want to go to http://myserver and be able to get Help Pages as the default home page, so the first thing a guest to http://myserver should see is the Help Page. I have a default route set up like this: public static void…
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
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 { …
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
20
votes
5 answers

Getting "No type was found that matches the controller named 'SampleSlashBaseService'" when trying to use WebAPI

I have a webapi project with a base ApiController named SlashBaseService: [RouteArea("uBase")] public abstract class SlashBaseService : ApiController { } The resulting dll is used in a WebForms project so I also have a WebActivator class with the…
azzlack
  • 1,191
  • 1
  • 9
  • 28
18
votes
2 answers

Greedy segment with .NET MVC 5 Attribute Routing

I would like to define a route as follows - [Route("clients/{*code}/{id:guid}/update")] public ActionResult Update(string code, Guid id) { } Code will be something like "foo/bar/xyz". Unfortunately, out-of-the-box MVC doesn't support greedy…
jameskind
  • 1,097
  • 2
  • 13
  • 28
1
2 3
24 25