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
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…
18
votes
3 answers

Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL

...guess I'm the first to ask about this one? Say you have the following routes, each declared on a different controller: [HttpGet, Route("sign-up/register", Order = 1)] [HttpGet, Route("sign-up/{ticket}", Order = 2)] ... you could do this in MVC…
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

Using WebAPI in LINQPad?

When I tried to use the Selfhosted WebAPI in LINQPad, I just kept getting the same error that a controller for the class didn't exist. Do I have to create separate assemblies for the WebAPI (Controllers/Classes) and then reference them in my…
NoLifeKing
  • 1,909
  • 13
  • 27
16
votes
3 answers

Multiple routes assigned to one method, how to determine which route was called?

I am working on a small ASP.NET MVC project at the moment. The project was released a few month ago. But changes should be implemented for usability and SEO reasons now. I decided to use attribute routing to create clean URLs. At the moment a…
John Doe
  • 415
  • 1
  • 4
  • 15
16
votes
1 answer

mvc5 attribute routing within area can't find view

When I'm inside Admin area and map my routes using attribute routing it cannot find view because it doesn't look inside actual area view folders but instead only global view folders. Only if I pass full path to view it then can display it, otherwise…
Stan
  • 25,744
  • 53
  • 164
  • 242
14
votes
3 answers

MVC Attribute routing with Url.Action not resolving route

I cannot get @Url.Action to resolve to the url I am expecting based on the attribute route I have applied: My action (SearchController but with [RoutePrefix("add")]) [Route("{searchTerm}/page/{page?}", Name = "NamedSearch")] …
Simon
  • 6,062
  • 13
  • 60
  • 97
14
votes
2 answers

Is it possible to change order of routes in routing table when using attribute routing?

So, I'm switching an area over from using AreaRegistration to using Attribute Routing. I'm running into an issue which appears to be caused by the order in which routes are loaded into the routing table. I'd solved the issue in AreaRegistration by…
David T. Macknet
  • 3,112
  • 3
  • 27
  • 36
13
votes
2 answers

Using Route instead of RoutePrefix at controller level in .net web api attribute routing

If I decorate this web api controller with the Route attribute I can hit the method [Route("api/v{version}/bank-accounts")] public class BankAccountsController : ApiController { [HttpGet] public HttpResponseMessage GetBankAccounts() { …
mitomed
  • 2,006
  • 2
  • 29
  • 58
12
votes
3 answers

Attribute Routing Inheritance

I always used this approach in my MVC applications before [Route("admin")] public class AdminController : Controller { } [Route("products")] public class ProductsAdminController :AdminController { [Route("list")] public IActionResult…
12
votes
1 answer

Multiple controllers with same URL routes but different HTTP methods

I've got a following two controllers: [RoutePrefix("/some-resources") class CreationController : ApiController { [HttpPost, Route] public ... CreateResource(CreateData input) { // ... …
12
votes
2 answers

Attribute routing in MVC 5 and optional defaults

Traditional routing defaults meant we were able to access these URLs and always end up on the same action: / /Home /Home/Index But today we would be writing something in these lines: [RoutePrefix("Home")] [Route("{action=Index}")] public class…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
12
votes
1 answer

Issues with Attribute Routing and Localization

I am using the newest version of the AttributeRouting package on Nuget to setup my routing for my ASP.Net MVC Project. I am creating a website that has two languages, English (primary) and Spanish (Secondary). The urls for the two languages are…
11
votes
3 answers

Attribute Routing - optional parameter not working?

According to http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx#optionals-and-defaults You can have optional parameters by adding a question mark (?) when using attribute routing. However it does not work for…
Adam Marshall
  • 3,010
  • 9
  • 42
  • 80
11
votes
1 answer

web api - message handler attribute routing

Does anyone know whether message handler can work simultaneously with attribute routing in Web API 2.x? I got a custom message handler to work using conventional routing, then after adding attribute routing, it stops working. I am not sure whether…
cng
  • 111
  • 5
1
2
3
24 25