简体   繁体   English

如何在另一个ASP.NET MVC项目中运行ASP.NET MVC项目

[英]How to run ASP.NET MVC project inside another ASP.NET MVC project

Let's say I have a MVC project where there is root folder MVC2 and. 假设我有一个MVC项目,其中有根文件夹MVC2和。 Now, I want another MVC project to that MVC2 folder and serve it. 现在,我想要另一个MVC项目到该MVC2文件夹并提供服务。

Below url should serve MVC2 project which is just a folder inside the root project. url下面应该提供MVC2项目,它只是根项目中的一个文件夹。 Root project is also MVC. 根项目也是MVC。

  • currentSite.com -> current mvc app currentSite.com - >当前的mvc app
  • currentSite.com/MVC2/ -> should run nested mvc app. currentSite.com/MVC2/ - >应该运行嵌套的mvc app。

I think there should be a webconfig setting which should make it work. 我认为应该有一个webconfig设置,它应该使它工作。

Thank you in advance. 先感谢您。 Any answer will be dearly appreciated. 任何答案都将非常感谢。

Is it possible? 可能吗? and if it is , is it possible to interact with each other. 如果是的话,是否可以互相交流。

I would strongly re-consider your architecture if you're having to embed MVC projects within one another. 如果您不得不将MVC项目嵌入其中,我会强烈重新考虑您的架构。 Depending on how closely related the two are, I would think about going in the following directions: 根据两者的密切关系,我会考虑按以下方向进行:

  1. MVC Areas - If both your projects are heavily linked, share a lot of the same code and resources then I would put them as two separate areas within your application. MVC领域 - 如果你的项目链接很多,共享很多相同的代码和资源,那么我会将它们作为应用程序中的两个独立区域。 Default area routing would give you currentSite.com/MVC2 aswell, provided your area was called MVC2. 如果您的区域名为MVC2,默认区域路由将为您提供currentSite.com/MVC2。 This approach means you'd always deploy both sites together as well (if that's something you need to consider). 这种方法意味着您总是将两个站点一起部署(如果这是您需要考虑的事项)。
  2. Separate Projects - If there's not a great deal of similarity between the two and you'd prefer to keep them separate, then simply have them both sit in one solution and migrate the common code into a separate class library project that sits within the same solution. 单独的项目 - 如果两者之间没有很大的相似性,并且您更愿意将它们分开,那么只需将它们放在一个解决方案中并将公共代码迁移到位于同一解决方案中的单独的类库项目中。 You can even compile your views using something like RazorGenerator if you need to share any views between the two projects. 如果您需要在两个项目之间共享任何视图,甚至可以使用RazorGenerator之类的东西编译您的视图。 This approach also means that you can deploy your sites separately as well should you need to. 此方法还意味着您可以根据需要单独部署站点。 To achieve the desired URL of currentSite.com/MVC2 in this scenario then you can simply set it up as a virtual directory in IIS. 要在此方案中获得所需的currentSite.com/MVC2 URL,您只需将其设置为IIS中的虚拟目录即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM