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

Commented Issue: [MvcAttributeRouting] Route attribute should not be inherited [1273]

$
0
0
When I use the following controller, I get the below exception:

Controller:
```
public class BaseController : Controller
{
[Route("base/about", Name="Base.About")]
public ActionResult About()
{
return Content("About");
}
}

public class DerivedController : BaseController
{

}
```

__Exception__:
```
A route named 'Base.About' is already in the route collection. Route names must be unique.
Parameter name: name

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: A route named 'Base.About' is already in the route collection. Route names must be unique.
Parameter name: name
```

__Case 2__: Controller-level route not hitting base action decorated with Route attribute

In the following controller, following is the status of requests:

GET base/about -> prints "About"
GET base/contact-> 404 Not Found (expected as there is explicit Route attribute)
GET base/hello -> prints "Contact"
GET derived/about -> prints "About"
GET derived/contact -> 404 Not Found (this is __not__ expected as Route should not be inherited)

```
[Route("base/{action}")]
public class BaseController : Controller
{
[HttpGet]
public ActionResult About()
{
return Content("About");
}

[HttpGet]
[Route("base/hello")]
public virtual ActionResult Contact()
{
return Content("Contact");
}
}

[Route("derived/{action}")]
public class DerivedController : BaseController
{
}
```
Comments: Fixed: https://aspnetwebstack.codeplex.com/SourceControl/changeset/4c15b153811aa5ee74533338ce627a1815790b80

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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