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
4
votes
2 answers

Attribute routing for POST in C# .NET

The following give me args=null when I POST with a body {"args": 222}. How can I get the member of the body into my variable args (or the entire body into a variable body) [HttpPost("{className}/{methodName}")] public ActionResult
Amarsh
  • 11,214
  • 18
  • 53
  • 78
4
votes
3 answers

Configuring ASP.NET MVC Attribute Routing for multi language site

I'm creating a MVC5 web site that should support multiple languages. The structure of the app is complex so I'm using Attribute Routing only. RouteConfig.cs is very simple: public static void RegisterRoutes(RouteCollection routes) { …
Aleksandr Ivanov
  • 2,778
  • 5
  • 27
  • 35
4
votes
1 answer

Getting attributes from current controller in owin middleware

Driving me a bit mad so hopefully someone can help me. Using WebAPI I can do something like this public class AuthenticationMessageHandler : DelegatingHandler { protected override async TaskSendAsync(HttpRequestMessage…
4
votes
2 answers

Attribute Routing in ASP.NET Core 1.0

Do I need to configure anything to use attribute routing in an ASP.NET Core 1.0 application? The following doesn't seem to be working for me. I was expecting to hit this method when I go to localhost:132/accounts/welcome public class…
Sam
  • 26,817
  • 58
  • 206
  • 383
4
votes
1 answer

AttributeRouting with IHttpControllerSelector - Api Versioning

I am trying to achieve api versioning using a CustomHttpControlSelector and AttributeRouting on asp.net webapi. What i am trying to do is distinguish controller's versions by it's namespaces. if a request is made to /api/v2/foo/bar i want it to…
bahadir
  • 709
  • 1
  • 11
  • 28
4
votes
3 answers

ActionLink generates wrong URL for Attribute Route

I'm using attribute routing to override the URLs in my controller. I have two actions, with the only difference being the ID present on the second. The rest of the parameters are optional query parameters used for searching. // RouteConfig.cs - I…
4
votes
1 answer

How to map different HTTP methods on the same url to different controllers?

I have my API for a small part of my application split over two controllers, because of (external) requirements on the casing of JSON data in the API (some requests should use camelCasing, while others should use PascalCasing). Now, I have a url…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
4
votes
2 answers

How can I use MVC5 attribute-based routes with a dot/period in them?

I have basically an out-of-the box MVC 5.2 app, with attribute-based routes enabled (calling routes.MapMvcAttributeRoutes(); from the provided RouteConfig.RegisterRoutes(RouteCollection routes) method). The following is in HomeController: …
gregmac
  • 24,276
  • 10
  • 87
  • 118
4
votes
1 answer

HttpControllerSelector not working with Attribute Routing

I'm using a custom HTTP controller selector to version my API. config.Services.Replace(typeof(IHttpControllerSelector), new NamespaceSelector(config)); Below is my controller with actions: [RoutePrefix("api/v1/messages")] public class…
Jango
  • 43
  • 1
  • 3
4
votes
1 answer

ASP MVC 5 Attribute routing not registering routes

Overview I'm currently trying to get attribute routing to work with my api controllers. It doesn't appear to be working, and I'm unsure why. I'm not sure if I'm missing a crucial step, or what the problem could be. Problem I'm trying to hit…
Josh Schultz
  • 897
  • 1
  • 13
  • 32
4
votes
1 answer

Asp.Net MVC Routing not working as expected in 5.1

I need to add the culture to the url to support localization in my asp.net mvc application with url's like: sample.com/en/about sample.com/en/product/2342 I recently upgraded my app from MVC 5.0 to 5.1 but the routing did not work as expected so I…
TugboatCaptain
  • 4,150
  • 3
  • 47
  • 79
4
votes
1 answer

Restricting auto Help Page contents when using Attribute Routing in Web API 2

I'm currently implementing a Web API using Web API 2's attribute routing (http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2). I am also using the Help Pages module in order to automatically generate…
jmsb
  • 4,846
  • 5
  • 29
  • 38
4
votes
1 answer

Mvc 5 Attribute Routing

I am trying to use the build-in attribute routing that comes with Mvc 5, previously I was using the AttributeRouting package on Nuget. But how do i set up routes by specifying whether it is for a Get or Post request? In AttributeRouting there was…
4
votes
1 answer

Unit Testing MVC 4 routes using AttributeRouting and MvcRouteTester

So I have been researching a lot about this but I cannot find a workaround for my problem I have a MVC4/Web API application and I'm using AttributeRouting 3.5.6 My app works fine. I was able to unit test the Web API routes using the following…
Jupaol
  • 21,107
  • 8
  • 68
  • 100
4
votes
1 answer

attributerouting limitations in webapi

In the documentation for attributerouting, there are a series of warnings that says that "performance enhancements when matching routes" does not work. What kind of performance enhancements are they talking about, and what does that mean in terms…
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460