I have two separate ASP.NET Core sites A1
and A2
based on a same shared library B
.
A1
and A2
are on a1.example.com and a2.example.com, and they have controllers with route templates looking like
A1
:
[HttpGet("/Feature1/{featureId}/EditEntry/{entryId}", Name = "EditFeature1Entry")]
public IActionResult EditFeature1Entry(long featureId, Guid entryId, string token)
{
[...]
}
In project A1
, I would generate an URL using
var url = Url.RouteUrl("EditFeature1Entry", new {featureId = 3, entryId = someGuid, token})
it would generate:
url = "/Feature1/3/EditEntry/someGuid?token=token"
But to build the same url from A2
, I need to generate the URL myself as the route is not registered in the project A2
(the controller is in project A1
).
What I would like to do is to put the templates somewhere in the library B
and use an URL generator to be able to do something like
var url = Url.RouteUrlFromTemplate("/Feature1/{featureId}/EditEntry/{entryId}", new {featureId = 3, entryId = someGuid, token}, "https", "a1.example.com", null);
in order to generate
url = "https://a1.example.com/Feature1/3/EditEntry/someGuid?token=token"
Is there any pre-built tool for that or should I do it myself? I feel I could use a large part of what exists in the current Url builder, but I would prefer to rely on the framework :)