I have an application that is multitenant, that is, I have multiple clients that use the application and share a single domain using folders. Like the following:
- http://www.mydomain.com/
client1/home/index - http://www.mydomain.com/
client2/home/index
I can’t use areas because the clients are not static, they register and they must be able to start using the application right away. I can’t use subdomains because in this case I don’t have dynamic control over the DNS.
That being said, how can I implement a custom route so that I don’t need to pass the client name every time I build an outgoing URL?
That is, I want this to be true:
@Url.Action("Index", "Home") -> www.mydomain.com/client1/home/index
without passing client1, something can resolve client1 because by the time I build this URL, this string will be a value of the current route values, because I’m already at the client1
How can I do that?
Now when you navigate to
/client1/Home/Indexand if inside theIndex.cshtmlview when you use:this will generate:
Same stands true for using the
Url.Actionhelper inside theIndexaction. It will preserve theclientroute value from the original request.