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
0
votes
1 answer

MVC WebAPI2 attribute routing using a path ending with a route parameter of type double

We are having an issue with WebApi2 attribute routing. We recently upgraded to MVC5 and Web Api 2. As part of the upgrade we shifted our Web Api to use Attribute routing. One of our API calls allows for data to be requested using a latitude and…
0
votes
1 answer

WebAPI route regex with optional parts

I want to map a WebAPI action method to urls on the format api/v2/l8n/{cultureCode}, but to avoid route collisions with other methods, I need to constrain the cultureCode parameter to only values matching the regex ^\w{2}(?:-\w{2})?$, i.e. sv and…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
0
votes
1 answer

MVC Attribute Routing Not working by changing the defaults

I have ` public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.LowercaseUrls = true; //routes.Add(new SubdomainRoute()); routes.MapRoute("Default",…
Zoinky
  • 4,083
  • 11
  • 40
  • 78
0
votes
1 answer

Default Route does not work after upgrading to MVC5 with Attribute Routing

After upgrading from MVC4 with AttributeRouting.net to MVC5 with MVC5's attribute routing, I can't seem to get the default route working so that http://server defaults to http://server/home/index . Browsing directly to /home/ or /home/index works…
Ken
  • 834
  • 9
  • 25
0
votes
2 answers

MVC 5 Route not found if parameter is passed in URL

I have following methods in my MVC controller: [HttpGet] public ActionResult Add(Guid b) { ViewBag.Title="Add Location"; //init some info return View("Edit",); } [HttpGet] public ActionResult Edit(Guid l) { …
0
votes
2 answers

Web API 2 attribute routing returning 404

I'm having trouble getting the Web API 2 attribute routing to work. I've been trying everything I could find this whole evening but I can't find the problem. What I want to achieve is the following: Make a POST request to…
VeldMuijz
  • 605
  • 5
  • 18
0
votes
3 answers

Attribute Routing failing - Web Api

I have two actions on a controller called JobController that has this Route Prefix [RoutePrefix("API/Job")] 1st Action (In order of precedence in controller) [Route("{jobId}/{user}"), System.Web.Http.HttpPost] public HttpResponseMessage…
MrBliz
  • 5,830
  • 15
  • 57
  • 81
0
votes
0 answers

Clear route data from Url.RouteUrl

In a view, if I use @Url.RouteUrl(MVC.Home.Actions.Foo()) where MVC.Home.Actions.Foo() is an ActionResult generated by T4MVC, then I expect to get /foo (which is what I've defined via attribute routing) but I actually get…
h bob
  • 3,610
  • 3
  • 35
  • 51
0
votes
1 answer

Web Api route {id:int}.xlsx is not found

I have an API endpoint that shall export some data as an Excel xlsx file. The URL I try to get is like this: localhost/service/resources/123.xlsx (because I think using this extension is a nice way to do it). But it always gives me a 404 Not…
AndersJH
  • 142
  • 1
  • 7
0
votes
1 answer

Get the route value from url in webapi attribute routing

I have a webAPI controller which is like Public class TestController:APIController { [Route(“Api/Test/{testId}/SubTest”)] Public void Post(int subTestid) { } } Our requirement is to get the value of testId from the url…
0
votes
2 answers

Prevent user from accessing an action which is accessible by code

I use the latest MVC, with attribute routing. When a user submits a contact form, it then redirects to a "thank you for submitting your info" view, with route foo.com/success. How can I configure it so that my code can redirect to that success…
h bob
  • 3,610
  • 3
  • 35
  • 51
0
votes
1 answer

AttributeRouting is it possible to capture / inside of a parameter?

First let me be clear I am talking about the independent project of AttributeRouting http://attributerouting.net/ and not the built-in attribute routing. Take this slightly modified version of their example code: public class SampleController :…
Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
0
votes
2 answers

MVC Attribute Routing

Is it possible to modify the template a route at runtime. Example: [Route("Home/Index")] public View Index() { return View(); } I have seen the new IDirectRouteProvider can the Template has no setter. Can i do this somewhere else? Thanks Steve
Steven Yates
  • 2,400
  • 3
  • 30
  • 58
0
votes
1 answer

Register routes assigned with Attribute Routing at runtime

I am working on the MVC application that loads controller at runtime from an external assembly with MEF and registers routes using custom route handler I have implemented with help of this…
cyrus-d
  • 749
  • 1
  • 12
  • 29
0
votes
1 answer

Attribute Route with constraint works locally but fails when deployed

I have a simple attribute route with three different path segments: [HttpGet] [GET("v{version:int}/{category}/{service}")] public async Task RouteMessage( string category, string service, int version = 1) { } While the…
nemec
  • 1,044
  • 9
  • 35