高级ASP.NET MVC路由方案 [英] Advanced ASP.NET MVC routing scenario

查看:192
本文介绍了高级ASP.NET MVC路由方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下部署要求的ASP.NET MVC应用程序:

I have an ASP.NET MVC app with the following deployment requirements:

URL结构必须类似于:

The URL structure must be something like:

http://server/app/[企业]/[社区]/ {controller}/{action}/...

http://server/app/[enterprise]/[communinty]/{controller}/{action}/...

我想我想做的是在MVC路由处理程序使用URL之前对其进行拦截,删除[enterprise]/[community]部分,然后允许MVC像原始的那样继续处理URL没有包含这两段.

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.

这是为什么:

该应用程序将多个门户网站公开给多个客户(企业),并且企业内的每个社区都有其自己的用户群.也可以通过将一个应用程序实例(二进制文件,内容,web.config)物理部署到每个[community]目录中来实现这种方案,但是出于后勤和性能方面的考虑,我认为我们不希望这样做.因此,我正在尝试通过路由技巧对其进行虚拟化.

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.

我们在IIS 7上,如果有什么不同的话.

We are on IIS 7, if that makes any difference.

推荐答案

您可以在默认路由之前使用以下路由

You can use the following route before the default route

routes.MapRoute(
    null,
    "{enterprise}/{community}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

然后您可以在操作方法中忽略{enterprise}和{community}参数.

You can then ignore {enterprise} and {community} parameters in your action methods.

这篇关于高级ASP.NET MVC路由方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆