ASP.NET MVC 3 - 处理多个域并共享单个代码库

发布于 2024-11-27 04:09:51 字数 743 浏览 0 评论 0原文

几天来我一直在想最好的方法,也想知道其他人的想法。

我们希望将所有公司网站重建和升级到 ASP.NET MVC 3,并在所有网站上(大部分)使用通用模板;我们已经在 MVC 3 中拥有一个站点,它将作为其他站点的捐赠站点。

起初,我只想复制/粘贴项目,用与每个站点相关的内容替换所有内容并完成它,但这将使将来更新模板/样式表/帮助程序变得更加困难 - 我们只有少数网站,所以这不是一个大问题。

想法 1

我想我想做的是拥有一个包含所有网站的单个项目,可能按区域分开以将它们分开,并使用路由将请求发送到各个域正确的位置并建立指向正确域的链接。

这将符合我们计划将所有网站链接在一起的方式 - 本质上是使用列出各个公司的所有网站通用的菜单,这些菜单将链接到包含与该特定公司相关的项目子菜单的公司域。

这就是它变得棘手的地方,因为我需要在域级别进行路由,而不是路由到当前域上的company2控制器(例如http://www.groupcompany.ex/company2 )我想将请求路由到company2自己的域 - http://www.company2.ex/{controller}/{action}/{id}

想法 2

并拥有一个托管任何帮助程序、CSS 和 JavaScript 等的通用项目。

或者,我可以在单个解决方案中为每个站点创建项目, 建议完全是疯狂的吗? (很可能就是这种情况)。

I've been wondering about the best way to do this for a couple of days and wondered what everyone else thought.

We want to rebuild and upgrade all our companies websites to ASP.NET MVC 3 and use a common template across them all (mostly); we already have one site in MVC 3 which will be the donor site for the others.

At first I was going to just copy/paste the project, replace all the content with content relevant to each site and be done with it but this would make updating the templates/stylesheets/helpers in future more difficult - we only have a handful of websites so it isn't a huge problem though.

Idea 1

What I think I would like to do would be to have a single project containing all of the websites, possibly split off by areas to keep them separated and use routing to send the requests to various domains to the right place and to build links pointing to the right domain.

This would fit with how we're planning on linking all the websites together - essentially with a menu common to all websites listing the various companies, these would link to the companies domain containing sub-menus of items related to that specific company.

This is where it becomes tricky, in that I would need to route at domain level - so rather than routing to the company2 controller on the current domain (e.g. http://www.groupcompany.ex/company2) I want to route requests company2's own domain - http://www.company2.ex/{controller}/{action}/{id}.

Idea 2

Alternatively I could create projects for each site in a single solution and have a common project which hosts any helpers, CSS and JavaScript etc.

Any thoughts on which way I should be doing this, and whether my suggestions are completely crazy? (which will likely be the case).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七色彩虹 2024-12-04 04:09:51

这是一个常见的要求。您所问的称为多租户。迄今为止,我还不知道对于如何在 MVC 中实现多租户达成共识。有多少问题可能就有多少解决方案。

这个问题我也没有解决得令我满意。然而,有许多博客文章对此进行了介绍。示例包括:

http: //weblogs.asp.net/zowens/archive/2010/05/26/multi-tenant-asp-net-mvc-introduction.aspx

http ://codeofrob.com/archive/2010/02/01/multi-tenancy-in-asp.net-mvc-why-do-we-want-to.aspx

这是我认为在某个时候需要将一些东西内置到框架中。希望这种情况能够发生,或者至少有人想出一个优雅的解决方案。

This is a common request. What you are asking about is called Multi-tenancy. To date, I don't know of any consensus on how to achieve Multi-tenancy in MVC. There are probably as many solutions as there are questions being asked about it.

I haven't solved this problem to my satisfaction either. However, there are a number of blog entries covering this. Examples include:

http://weblogs.asp.net/zowens/archive/2010/05/26/multi-tenant-asp-net-mvc-introduction.aspx

http://codeofrob.com/archive/2010/02/01/multi-tenancy-in-asp.net-mvc-why-do-we-want-to.aspx

This is something that I think needs to be built into the framework at some point. Hopefully, that happens, or at least someone comes up with an elegant solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文