高级 ASP.NET MVC 路由场景
我有一个 ASP.NET MVC 应用程序,具有以下部署要求:
URL 结构必须类似于:
http://server/app/[enterprise]/[communinty]/{controller}/{action}/...
我想我想要做的是在MVC路由之前拦截URL handler 接手它,删除 [enterprise]/[community] 部分,然后允许 MVC 继续处理,就好像原始 URL 不包含这两个段一样。
原因如下:
该应用程序向多个客户(企业)公开多个门户,并且企业内的每个社区都有自己的用户群。这种方案也可以通过将一个应用程序实例(二进制文件、内容、web.config)物理部署到每个 [community] 目录中来实现,但出于逻辑和性能方面的原因,我认为我们不想走这条路。所以我试图通过路由技巧来虚拟化它。
任何有关如何实施此计划或替代解决方案的建议将不胜感激。
如果这有什么区别的话,我们使用的是 IIS 7。
I have an ASP.NET MVC app with the following deployment requirements:
The URL structure must be something like:
http://server/app/[enterprise]/[communinty]/{controller}/{action}/...
What I think I want to be able to do is intercept the URL before the MVC route handler gets its hands on it, remove the [enterprise]/[community] parts, and then allow MVC to continue processing as if the original URL had not contained those two segments.
Here's why:
The application exposes multiple portals to multiple customers (enterprises), and each community within an enterprise has its own user population. This kind of scheme could also be served by physically deploying one application instance (binaries,content,web.config) into each [community] directory, but for logistical and performance reasons, I don't think we want to go down this path. So I'm trying to virtualize it through routing tricks.
Any suggestions on how to go about this scheme, or alternate solutions would be appreciated.
We are on IIS 7, if that makes any difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是使用 IIS 重写模块的可能解决方案。这可能不是最好的方法,但可能有效。 MVC 路由中是否有更简单/更好的选项?没有把握。我自己才刚刚开始这样做。
使用“http://server.com/app/enterprise/community/controller/action /”为例。
会发生什么:
网址:
http://server.com/controller/action/
浏览器现在显示:
http://server.com/controller/action/
重建它以获取正确的
内容。用户浏览器显示:
http://server.com/controller/action/ ;
IIS 返回:
http://server.com/app/enterprise/community/controller/action/< /a>
安装 IIS 重写模块后,所有这些都将位于 web.config 中:
注意:只是快速完成此操作,尚未测试。
Here is a possible solution with IIS Rewrite module. It may not be the best approach, but it may work. Is there an easier/better option within the MVC routing? Not sure. Only just started doing that myself.
Using "http://server.com/app/enterprise/community/controller/action/" as an example.
What happens:
URL:
http://server.com/controller/action/
browser now shows:
http://server.com/controller/action/
rebuild it to grab the correct
content. User's browser shows:
http://server.com/controller/action/ ;
IIS returns:
http://server.com/app/enterprise/community/controller/action/
All of this would be in the web.config once the IIS rewrite module is installed:
Note: Just did this quick, haven't tested.
您可以在默认路由之前使用以下路由,
然后可以忽略操作方法中的 {enterprise} 和 {community} 参数。
You can use the following route before the default route
You can then ignore {enterprise} and {community} parameters in your action methods.