在单个解决方案中混合使用VB ASP.NET和C#ASP.MVC项目

时间:2022-07-16 01:40:15

Background

We are a TDD team who have inherited a legacy ASP.NET application and are trying to bring it under control by separating presentation, business and data access concerns and thereby improving testability. We have had some success using an MVP pattern for newly added pages but are investigating the MS MVC framework to see if it gives us any benefit over MVP. Importantly, we would want the new MVC work to be in C# while the legacy application is in VB. We have looked at this blog entry which mostly achieves what we want but doesn't allow us to code in C#. Additionally, there are a number of blog entries about partitioning a single web application across multiple projects which looked useful (here)

我们是一个TDD团队,他们继承了遗留的ASP.NET应用程序,并试图通过分离表示,业务和数据访问问题来控制它,从而提高可测试性。我们已经使用MVP模式为新添加的页面取得了一些成功,但是正在调查MS MVC框架,看它是否给我们带来了超过MVP的任何好处。重要的是,我们希望新的MVC工作在C#中,而遗留应用程序在VB中。我们已经看过这个博客条目,它主要实现我们想要的但不允许我们用C#编写代码。此外,有许多关于跨多个项目划分单个Web应用程序的博客条目看起来很有用(这里)

Question

Can you create a working prototype consisting of a single web application made up of two projects (the default VB ASP.NET project and the default C# MVC project) and have them work nicely together. I have not been able to do this successfully (I think due to routing issues). If you can I'd like to see your web.config and global.asax files.

你能创建一个工作原型,由一个由两个项目组成的Web应用程序组成(默认的VB ASP.NET项目和默认的C#MVC项目)并让它们很好地协同工作。我无法成功地做到这一点(我认为由于路由问题)。如果你能,我想看看你的web.config和global.asax文件。

2 个解决方案

#1


The default MVC app contains two important bits of code in the root of the project, and they will need to exist in the root of your app too:

默认的MVC应用程序在项目的根目录中包含两个重要的代码,它们也需要存在于应用程序的根目录中:

  1. The Global.asax - the code behind sets up the all the routing.
  2. Global.asax - 后面的代码设置所有路由。

  3. The Default.aspx - the code behind fires up the MvcHttpHandler, and starts you off down the MVC routes
  4. Default.aspx - 后面的代码激活MvcHttpHandler,并启动你关闭MVC路由

Both of these will need to be in the root of your website (or be set up in a similar way somewhere) to load up correctly and start handling all the routing properly - you should also ensure that your routes are specific enough not to catch the legacy apps pages.

这两个都需要在您的网站的根目录(或以某种类似的方式设置)正确加载并开始正确处理所有路由 - 您还应该确保您的路由足够具体,不要抓住旧版应用页面。

#2


If you're not doing pure MVC, don't bother. The advantage of the ASP.NET MVC framework is that it separates the layers of an application and gives you more control over each of them. What I think you're doing is launching new functionality in MVC only because it is fresh and new, but you wouldn't use the advantages it gives you. I think it would become even more unmaintainable and this is not the point. This might not be the case, I don't know what is it you're trying to achieve with this MVC project, if so, please elaborate.

如果你没有做纯MVC,不要打扰。 ASP.NET MVC框架的优点是它可以分离应用程序的各个层,并使您可以更好地控制每个层。我认为你正在做的是在MVC中启动新功能只是因为它是新鲜的,但你不会利用它给你的优势。我认为这将变得更加难以维持,这不是重点。可能不是这种情况,我不知道你想用这个MVC项目实现什么,如果有的话,请详细说明。

#1


The default MVC app contains two important bits of code in the root of the project, and they will need to exist in the root of your app too:

默认的MVC应用程序在项目的根目录中包含两个重要的代码,它们也需要存在于应用程序的根目录中:

  1. The Global.asax - the code behind sets up the all the routing.
  2. Global.asax - 后面的代码设置所有路由。

  3. The Default.aspx - the code behind fires up the MvcHttpHandler, and starts you off down the MVC routes
  4. Default.aspx - 后面的代码激活MvcHttpHandler,并启动你关闭MVC路由

Both of these will need to be in the root of your website (or be set up in a similar way somewhere) to load up correctly and start handling all the routing properly - you should also ensure that your routes are specific enough not to catch the legacy apps pages.

这两个都需要在您的网站的根目录(或以某种类似的方式设置)正确加载并开始正确处理所有路由 - 您还应该确保您的路由足够具体,不要抓住旧版应用页面。

#2


If you're not doing pure MVC, don't bother. The advantage of the ASP.NET MVC framework is that it separates the layers of an application and gives you more control over each of them. What I think you're doing is launching new functionality in MVC only because it is fresh and new, but you wouldn't use the advantages it gives you. I think it would become even more unmaintainable and this is not the point. This might not be the case, I don't know what is it you're trying to achieve with this MVC project, if so, please elaborate.

如果你没有做纯MVC,不要打扰。 ASP.NET MVC框架的优点是它可以分离应用程序的各个层,并使您可以更好地控制每个层。我认为你正在做的是在MVC中启动新功能只是因为它是新鲜的,但你不会利用它给你的优势。我认为这将变得更加难以维持,这不是重点。可能不是这种情况,我不知道你想用这个MVC项目实现什么,如果有的话,请详细说明。