Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: [AttributeRouting]Route not being added to route collection [1005]

$
0
0
__Note__: This behavior exists even in MVC attribute routing too. I haven't filed a new bug for it, but would like to use this bug.

In the following scenario, the Get() action on ReproController, which is decorated with an attribute route is _not_ being added to the route collection.

On the other hand, the Get() action on the WorkingConroller is added to the route collection as expected.

Expected: Get() action on ReproController should be part of route collection
Actual: Not added to route collection.

```
public class ReproController : ApiController
{
//NOTE: NOT added to route collection
[HttpGet(RouteName="GetAllValues")]
public string Get()
{
return "Repro.GetAllValues";
}
}

public class WorkingController : ApiController
{
//NOTE: ADDED to route collection. Notice the empty route template
[HttpGet("", RouteName = "GetAllValues2")]
public string Get()
{
return "Working.GetAllValues2";
}
}
```
Comments: Ideally we would be able to make something like the following work so that we don't have to overburden ApiControllers with too many attributes: [DefaultRoute("api/values/{id?}")] public class ValuesController : ApiController { // GET api/values public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET api/values/5 public string Get(int id) { return "value"; } // POST api/values public void Post([FromBody]string value) { } // PUT api/values/5 public void Put(int id, [FromBody]string value) { } // DELETE api/values/5 public void Delete(int id) { } } If an action has an explicit route attribute, it would override the default route specified on the controller.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>