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

Created Unassigned: Web Api attribute routing is adding NonAction decorated method to route collection [1151]

$
0
0
__Scenario__:
A user sometimes would like to keep some methods public in his controller but would not like it to be invoked by end users, so he decorates it with [NonAction] attribute.

__Issue__:
In the following scenario, a route is being added to the route collection:
```
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
[NonAction]
public IEnumerable<string> GetAllValues()
{
return new string[] { "value1", "value2" };
}
}
```
Following would be how the route could look like in the route collection:
config.Routes.MapHttpRoute("routeName", "api/values", new { }, new { }, new { actions = [Values.GetAllValues()] });

__Workaround__:
Create custom route builder deriving from the default one. Override one of the "BuildHttpRoute" methods which provides access to the action descriptor and using it you can check to see if there are any NonAction attributes decorated and if present, ignore adding the route to the route collection.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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