0

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 :)

Jean
  • 4,911
  • 3
  • 29
  • 50

1 Answers1

0

But it seems your two sites are two subdomains of a domain and you can see this links too: https://www.crookm.com/journal/2018/routing-by-subdomain-in-asp-net-core-mvc/

Is it possible to make an ASP.NET MVC route based on a subdomain?

https://forums.asp.net/t/2106373.aspx?Enable+Subdomain+routing+on+ASP+NET+MVC+area

And it is a subdomain routing project in github:

https://github.com/mariuszkerl/AspNetCoreSubdomain

isaeid
  • 543
  • 5
  • 26
  • Thanks for your answer, however most of these use Controller/Action/... standard route. I would like a solution for any custom route template, not especially registered, that could be part of another site. The `RouteUrlFromTemplate` tool does not exist, that is a method I would like to have. – Jean Apr 07 '19 at 20:52
  • Subdomains are on different sites – Jean Apr 07 '19 at 21:01
  • I'm so sorry! Why you don't trying to make the RouteUrlFromTemplate as a new routing tool? – isaeid Apr 08 '19 at 04:28