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

Commented Issue: In web api attribute routing, force users to supply HttpVerbAttribute base routetemplates on actions, if controller is decorated with RoutePrefix [1152]

$
0
0
__For the following case__:
```
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
public IEnumerable<string> GetAllValues()
{
return new string[] { "value1", "value2" };
}
}
```
Following is how the route looks like(_note_ that there are no httpMethod route constraints):
config.Routes.MapHttpRoute("routeName", "api/values", new { }, new { }, new { actions = [Values.GetAllValues()] });

__Reasons for this ask__:
1. In the above scenario, appropriate method constraint is not being added to the route.
2. Keeping the behavior consistent with how MVC attribute routing does, which is, it does not add any route to the collection if an action is not decorated with the verb attribute.
3. Also, I am seeing a NullRef exception when the controller looks like below:
```
RoutePrefix("api/values")]
public class ValuesController : ApiController
{
public IEnumerable<string> GetAllValues()
{
return new string[] { "value1", "value2" };
}

public string GetSingle(int id)
{
return "value";
}
}
```

__Exception__:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Http.HttpConfigurationExtensions.CreateRouteEntries(HttpControllerDescriptor controllerDescriptor) in c:\WebstackRuntime\Runtime\src\System.Web.Http\HttpConfigurationExtensions.cs:164
System.Web.Http.HttpConfigurationExtensions.MapHttpAttributeRoutes(HttpConfiguration configuration, HttpRouteBuilder routeBuilder) in c:\WebstackRuntime\Runtime\src\System.Web.Http\HttpConfigurationExtensions.cs:91
System.Web.Http.HttpConfigurationExtensions.MapHttpAttributeRoutes(HttpConfiguration configuration) in c:\WebstackRuntime\Runtime\src\System.Web.Http\HttpConfigurationExtensions.cs:63
MvcAppSample.WebApiConfig.Register(HttpConfiguration config) in c:\Users\kichalla\Documents\Visual Studio 2013\Projects\MvcAppSample\App_Start\WebApiConfig.cs:17
MvcAppSample.MvcApplication.Application_Start() in c:\Users\kichalla\Documents\Visual Studio 2013\Projects\MvcAppSample\Global.asax.cs:21
Comments: Fixed: https://aspnetwebstack.codeplex.com/SourceControl/changeset/f827886fbfff38a8932a29f5018e3223c0e98d10

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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