Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asp-action and asp-controller not resolving route with attribute routing. #19927

Closed
ramanmittal opened this issue Mar 17, 2020 · 4 comments
Closed
Assignees
Labels
affected-most This issue impacts most of the customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-routing severity-minor This label is used by an internal tool
Milestone

Comments

@ramanmittal
Copy link

ramanmittal commented Mar 17, 2020

I am working on a multi-tenant application in which I am using routing like this
endpoints.MapControllerRoute( name: "default", pattern: "{tenant}/{controller=Home}/{action=Index}/{id?}");
I have an action in which I am applying attribute routing.
public class DefaultController : Controller { [Route("{tenant}/asdf")] public IActionResult Index() { return Content("asdf"); } }
The issue is that when I creating a action link in a Razor view using tags
<a asp-action="Index" asp-controller="Default">asdf</a>
It is generating the wrong output <a href="/a1/Default">asdf</a>
But it should generate <a href="/a1/asdf">asdf</a>

@ramanmittal ramanmittal changed the title Url.Action not resolving route with attribute routing. asp-action and asp-controller not resolving route with attribute routing. Mar 17, 2020
@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Mar 18, 2020
@javiercn
Copy link
Member

@ramanmittal thanks for contacting us.

@rynowak is this an ambient values thing? I'm not sure why the conventional route would be picked over the attribute route and if the attribute route should be picked over it.

Is the conventional route mapped with a higher order than the attribute route?

@rynowak
Copy link
Member

rynowak commented Mar 18, 2020

If you turn logging up to debug for Microsoft there's a lot more info about what's going on. This is almost certainly relying on the ambient values behavior that changed in 3.0. We're planning to add a feature for scenarios like this.

Attribute routes will (by default) have higher order than conventional routes.

@ramanmittal
Copy link
Author

If you turn logging up to debug for Microsoft there's a lot more info about what's going on. This is almost certainly relying on the ambient values behavior that changed in 3.0. We're planning to add a feature for scenarios like this.

Attribute routes will (by default) have higher order than conventional routes.

I observed that this issue is occurring when I am applying {tenant} param in route templates. When I am not using then it is giving priority to the attribute route and generate correct URLs.

@javiercn javiercn added affected-most This issue impacts most of the customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool labels Oct 9, 2020
@ghost
Copy link

ghost commented Dec 8, 2020

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Dec 8, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 7, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-most This issue impacts most of the customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-routing severity-minor This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

4 participants