有没有办法可以实现自定义路由,以便自动传递某些路由值?
我有一个多租户应用程序,也就是说,我有多个客户端使用该应用程序并使用文件夹共享单个域。如下所示:
- www.mydomain.com/
client1
/home/index - www.mydomain.com/
client2
/home/index
我无法使用区域,因为客户端是不是静态的,他们注册并且必须能够立即开始使用该应用程序。我无法使用子域,因为在这种情况下我无法动态控制 DNS。
话虽如此,如何实现自定义路由,以便每次构建传出 URL 时都不需要传递客户端名称?
也就是说,我希望这是真的:
@Url.Action("Index", "Home") -> www.mydomain.com/client1/home/index
在不传递 client1
的情况下,某些东西可以解析 client1
因为当我构建此 URL 时,该字符串将是当前的值路由值,因为我已经在 client1
我该怎么做?
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:
- www.mydomain.com/
client1
/home/index - 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,当您导航到
/client1/Home/Index
并且在Index.cshtml
视图中使用时:这将生成:
使用
也是如此
帮助器。它将保留原始请求中的Index
操作中的 Url.Actionclient
路由值。Now when you navigate to
/client1/Home/Index
and if inside theIndex.cshtml
view when you use:this will generate:
Same stands true for using the
Url.Action
helper inside theIndex
action. It will preserve theclient
route value from the original request.