Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

No route candidate coming back to Mvc when it should be resolvable #316

Closed
NinoFloris opened this issue May 29, 2016 · 4 comments
Closed
Assignees
Milestone

Comments

@NinoFloris
Copy link

NinoFloris commented May 29, 2016

Ok given these routes, and this url http://example.com/ptslug/slug it should be clear that the bottom most route and accompanied action should be triggered.

        [HttpGet]
        public Task<IEnumerable<Model>> GetAll(...) { ... }

        [HttpGet("{ptSlug}")]
        public Task<IEnumerable<Model>> GetAllByPtSlug(...) { ... }

        [HttpGet("{id:int}")]
        public Task<Model> GetById(...) { ... }

        [HttpGet("{ptSlug}/{slug}")]
        public Task<Model> GetByPath(...) { ... }

However, as I have debugged the http://github.com/aspnet/Mvc project it does not even get to the point of selecting an action, which normally happens in the ActionSelector. Breakpointing this class revealed that it did not get entered.

Changing this routes' Order to any number (either putting it in front of all the other routes or behind them) fixes this.

        [...]

        [HttpGet("{ptSlug}/{slug}", Order=1)]
        public Task<Model> GetByPath(...) { ... }

In turn it enters the ActionSelector and onwards into my code.

What is going on here?

@javiercn
Copy link
Member

Investigating

@dougbu
Copy link
Member

dougbu commented May 30, 2016

@NinoFloris did you intend ptSlug to be that literal string or a variable? That is should the last attribute be [HttpGet("ptSlug/{slug}")] or perhaps [HttpGet("ptSlug/slug")]?

@NinoFloris
Copy link
Author

I mean for it to be a variable, as with slug.
Really like this:
[HttpGet("{ptSlug}/{slug}")]

And to clarify the given url:

http://example.com/anyvariableptslug/anyvariableslug

@javiercn
Copy link
Member

javiercn commented Jun 3, 2016

We weren't iterating the route matching tree correctly in some scenarios, we were returning the previous node. The fix was to replace the counter that was being used an use the Depth property on the node instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants