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

Edited Issue: MVC attribute routing fails for multiple routes with the same URL, and no specific RouteName set. [1146]

$
0
0
__Scenario__:
User decorates the controller and actions with attributed routes and expects the applicaiton to work.

__Issue__:
Consider the following two actions in AccountController(shortened for brevity):
```
[RoutePrefix("Account")]
public class AccountController : Controller
{
//
// GET: /Account/Register
[AllowAnonymous]
[HttpGet("Register")]
public ActionResult Register()


//
// POST: /Account/Register
[HttpPost("Register")]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
}
```
After the above changes, when the application is launched, we currently get the following
__Error__:
"A route named 'Account/Register' is already in the route collection. Route names must be unique.
Parameter name: name"

__Expected__:
The above error should not be occuring and the application should be launched successfully.

__Reason__:
In MVC, it appears that most of the Url link generation happens via the "Url.Action" or "Html.Actionlink" helpers, where users can specify action name, controller name etc. Since these helpers are used more commonly than "Url.RouteUrl" which expects a route name, we should not force the users to supply a unique route name upfront. We should generate unique names automatically just like how Web API's attribute routing works.

Even in Web API, we do not expect the users to depend on our uniquely generated names to generate links. If indeed they would like to have a friendly name for a particular route, they are expected to explicitly supply them. This way at least we do not provide a bad user experience upfront like currently MVC attribute routing does.


Viewing all articles
Browse latest Browse all 7215

Trending Articles



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