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

WebApi2 Attribute Routing doesn't work unless controller classes are named in a specific manner

I was debugging an issue with attribute routing giving 404s for known-good routes. Well, known-good to me, but they weren't being picked up by the framework. I was grouping my controllers/models into logical units, e.g.: Auth Models …
Josh M.
  • 26,437
  • 24
  • 119
  • 200
0
votes
1 answer

Take parameter from request with attribute routing

Hy, I'm using Attribute Routing for my project and I don't know how I can take the value of the parameter from the URL. I tried using the Request but I can't find it anywhere. When I make GET: http://localhost:60163/courses/courseId=1 how can I…
0
votes
0 answers

Overriding UseBufferedInputStream in Web Api when Attribute Routing is in use

I want to override the buffered input stream for a particular end point which is responsible for upload the files. I've been following the advice in the great article…
Mike D
  • 220
  • 1
  • 4
  • 12
0
votes
1 answer

C# WebApi AttributeRouting ; also possible to specify optional nullable integer

Following this page : http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx These routes are supported: [Route("users/{id:int}")] public ActionResult GetUserById(int id) { . . . } [Route("users/{id?}")] public…
Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
0
votes
0 answers

Prevent web api from falling back to "default GET" route

I am using attribute routing with the following routes: [RoutePrefix("api/books/{id}")] public BooksController : ApiController { [Route("")] public IHttpActionResult GetByTitle(int id,string title); [Route("")] public…
Sul Aga
  • 6,142
  • 5
  • 25
  • 37
0
votes
1 answer

Route attributes overriding route

Here's my route: routes.MapRoute("Login", "", new { action = "Login", controller = "Authentication"}) .DataTokens = new RouteValueDictionary(new { area = "Authentication" }); routes.MapMvcAttributeRoutes(); Here is the controller…
Ian Warburton
  • 15,170
  • 23
  • 107
  • 189
0
votes
1 answer

Same route parameters with different controllers' action methods causes an error in Asp .Net MVC

I m using attribute routing feature of Asp .Net Mvc. My first action is like below which is placed in SurveyController [Route("{surveyName}")] public ActionResult SurveyIndex() { return View(); } And my second action is like…
revolver
  • 95
  • 1
  • 8
0
votes
2 answers

Routing for Particular Action Adds 'Home' In Front of Action

I'm having an odd issue with routing in a basic ASP/MVC project. I have a bunch of nav items setup:
  • Home
  • Fire
  • 0
    votes
    0 answers

    AttributeRouting returns Forbidden when route mirrors directory structure

    I'm using MVC 5.2.2 with AttributeRouting. Imagine the code below, for example: public sealed class DocumentsController : Controller { [Route("documents")] [HttpGet] public ActionResult Index() { return View(); } } This…
    crush
    • 16,713
    • 9
    • 59
    • 100
    0
    votes
    1 answer

    MVC custom (attribute) routing with an optional parameter does not work

    My controller looks like this: [HttpGet] [Route("{brand}/{category}/{subcategory?}/{productid:int:min(9000)}", Name="ProductDetails")] public ActionResult Details(int productid) { //...} I also tried without the questionmark on the end of the…
    JP Hellemons
    • 5,977
    • 11
    • 63
    • 128
    0
    votes
    1 answer

    Attributed Routing with multiple parameters in Web API 2

    I am trying attributed routing with Web API 2. I have defined a route prefix and I have two methods. The first one works but the second one fails [RoutePrefix("api/VolumeCap")] public class VolumeCapController : ApiController { …
    Noor
    • 155
    • 2
    • 12
    0
    votes
    1 answer

    Using '.' in Web Api using Attribute Routing is giving 404 error

    I am using Routing Attribute to try to send a string via url to my web Api. I have a Route defined as [Route("Search/{searchText}")] I am expecting a string value as searchText. It seems to be working fine but I am getting an error if there is a…
    0
    votes
    1 answer

    MVC5 get area name when using attribute routing

    I have an old MVC3 site where I was able to get the area of a route by using the following code: object oArea; RouteData.DataTokens.TryGetValue("area", out aArea); I am creating a new MVC5 application and have started to use attribute based…
    0
    votes
    2 answers

    RoutePrefix Order alternative for WebAPI 2

    In WebAPI you can specify an Order in RouteAttribute to determine which order the routes are matched in. For example the below will match /other to GetOther before matching /blah to GetByName [HttpGet, Route("{name}", Order = 1)] public string…
    dav_i
    • 27,509
    • 17
    • 104
    • 136
    0
    votes
    1 answer

    Accessing MVC5 Attribute routing parameter in a custom attribute?

    I'm having a bit of trouble with a WebAPI project using MVC5 and attribute routing. Essentially, this is what I want to do: [Route("Products/{CategoryId}")] [ClaimsAuthorize([{CategoryId}], ClaimsEnum.CanViewProducts)] public Products Get(){ …