带有子域的路由
我有一个 MVC 网站,它有 3 个主要组件
- 成员区域,路径为 /Member/{controller}/{action}/{id}
- 单个页面将响应任何子域,例如 user1.example.com/{controller}/ {action}/{id}, user2.example.com/{controller}/{action}/{id}
- 将响应 www.example.com/{controller}/{action}/{id 下任何网址的主网站 ?
处理允许上述 3 项共存的路由的最简单方法是什么 我已经尝试了 global.asax.cs 文件中的许多 MapRoutes,并且还基于 RouteBase 创建了一个新类,但运气不佳。
I have an MVC website which has 3 main components
- Member area which has the path /Member/{controller}/{action}/{id}
- Individual pages which will respond to any subdomain, e.g. user1.example.com/{controller}/{action}/{id}, user2.example.com/{controller}/{action}/{id}
- Main website which will respond to any url under www.example.com/{controller}/{action}/{id}
What is the easiest way to handle the routes that will allow the above 3 items to co-exist? I have tried many MapRoutes from the global.asax.cs file and also making a new class based on RouteBase but not having much luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正朝着正确的方向前进 - 本质上您需要创建一个自定义路由来查看请求并构造路由值字典。不过,有人已经创建了一个很好的实现,它允许您在域本身中包含占位符,而不是重新发明轮子,如下所示:
http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx
It sounds like you're heading in the right direction - essentially you need to create a custom route which looks at the request and constructs the route value dictionary. Rather than reinvent the wheel though, someone has already created a nice implementation which allows you to include placeholders in the domain itself like so:
http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx