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

LinkGenerator does not take in consederation the site prefix #16259

Closed
MikeAlhayek opened this issue Jun 6, 2024 · 4 comments
Closed

LinkGenerator does not take in consederation the site prefix #16259

MikeAlhayek opened this issue Jun 6, 2024 · 4 comments
Labels

Comments

@MikeAlhayek
Copy link
Member

Describe the bug

This is something that require investigation. When when using LinkGenerator to create a link for a tenant that use "prefix" for the host. It generates a path without the /tenant-prefix.

like this for example:

If you have a tenant setup with no host but with blog1 prefix. then creating a link like this

var url = _linkGenerator.GetPathByAction("Index", "Admin", new { area = "OrchardCore.Settings", groupId = "admin" });

creates

/Admin/Settings/admin

instead of

blog1/Admin/Settings/admin

Orchard Core version

Expected behavior

I expect the generated URL to be as follow

blog1/Admin/Settings/admin
@Piedone
Copy link
Member

Piedone commented Jun 6, 2024

Latest main?

@MikeAlhayek
Copy link
Member Author

Yes

@MikeAlhayek
Copy link
Member Author

I think this is a limitation of the extension method used. If you look at the implementation, it does not use the HttpContext when generating the URL

https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/Routing/ControllerLinkGeneratorExtensions.cs#L187-L204

The problem with that for us is that the URL-prefix will never be considered here since this is something we add to the HttpContext.

The workaround is to use the extension method that accepts the HttpContext as the first argument.

https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/Routing/ControllerLinkGeneratorExtensions.cs#L134-L160

So instead of doing this

var url = _linkGenerator.GetPathByAction("Index", "Admin", new { area = "OrchardCore.Settings", groupId = "admin" });

do this

var url = _linkGenerator.GetPathByAction(_httpContextAccessor.HttpContext, "Index", "Admin", new { area = "OrchardCore.Settings", groupId = "admin" });

@sebastienros
Copy link
Member

So there is no issue, right? We just need to call the extension method with the HttpContext when using LinkGenerator. Please re-open if I missunderstood.

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

No branches or pull requests

3 participants