asp.net-mvc 逐步将现有 ASP.NET 站点转换为 MVC 的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/211744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 22:47:38  来源:igfitidea点击:

Best way to gradually convert an existing ASP.NET site to MVC

asp.net-mvc

提问by LBugnion

Please keep in mind that this is new for me and I might have missed something important.

请记住,这对我来说是新的,我可能错过了一些重要的东西。

I have an existing website, based on an ASP.NET web application. I am now using ASP.NET MVC for new development, and intend to gradually replace the bulk of the pages with MVC based pages.

我有一个基于 ASP.NET Web 应用程序的现有网站。我现在正在使用 ASP.NET MVC 进行新的开发,并打算逐步用基于 MVC 的页面替换大部分页面。

I have two issues here:

我这里有两个问题:

1) I need to replace the pages gradually, because I cannot convert everything at once. 2) Existing URLs (of physical files) should be preserved if possible.

1)我需要逐步更换页面,因为我无法一次转换所有内容。2) 如果可能,应保留现有的(物理文件的)URL。

The way I see it, I have the following options:

在我看来,我有以下选择:

1) Create a brand new MVC web application in the root of the web site, and then include existing HTML/ASPX/ASMX/... pages to that. This way, the routes are always relative to the root of the web site.

1) 在网站的根目录中创建一个全新的 MVC Web 应用程序,然后将现有的 HTML/ASPX/ASMX/... 页面包含到该应用程序中。这样,路由总是相对于网站的根目录。

2) Modify the existing Global.asax, Web.config, Default.aspx (and so on) to switch the MVC handler on for routing, and then publish my MVC application to a subfolder.

2) 修改现有的 Global.asax、Web.config、Default.aspx(等等)以打开 MVC 处理程序以进行路由,然后将我的 MVC 应用程序发布到子文件夹。

What is the easiest way to do that, and am I missing something?

最简单的方法是什么,我是否遗漏了什么?

Thanks, Laurent

谢谢,洛朗

采纳答案by Mouffette

Like you, I'm tackling this same problem. A few things I ran into I've posted about here https://stackoverflow.com/users/84825/mouffetteand they are mainly related to SETUP. The best thing to do is start a new MVC project and compare the files and structure to your existing ASP.NET application. When in doubt just move over line by line and web.config's and eventually you'll get it ;-)

和你一样,我也在解决同样的问题。我遇到的一些事情我已经在这里发布了https://stackoverflow.com/users/84825/mouffette,它们主要与 SETUP 相关。最好的做法是启动一个新的 MVC 项目并将文件和结构与现有的 ASP.NET 应用程序进行比较。如果有疑问,只需逐行和 web.config 移动,最终你会得到它;-)

Once you have the plumbing working you then can focus on MVC and it just works side by side.

一旦管道工作正常,您就可以专注于 MVC,它只是并排工作。

These links have also helped:

这些链接也有帮助:

http://media.wiley.com/assets/1539/15/professionalaspnet35mvc_chapter13.pdfhttp://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf

http://media.wiley.com/assets/1539/15/professionalaspnet35mvc_chapter13.pdf http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf

and you've already found the best site...stackoverflow.

你已经找到了最好的网站...stackoverflow。

回答by Jason Stangroome

Scott Hanselman has a good blog post discussing how to combine MVC with Web Forms and other ASP.NET technologies. http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx

Scott Hanselman 有一篇很好的博客文章,讨论了如何将 MVC 与 Web 窗体和其他 ASP.NET 技术相结合。 http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx

回答by Chris Conway

It really depends on the state of your existing web application. If it's mostly just business logic baked into your code-behinds, then you're probably better off with a re-write. If you've got a really decent code separation of your data object models and business layer from your code behinds, then you're ahead of the game on this transition. Unfortunately, this is a really difficult question to answer succinctly and is fairly subjective based on your current state.

这实际上取决于您现有 Web 应用程序的状态。如果它主要只是融入您的代码隐藏中的业务逻辑,那么您最好重新编写。如果您的数据对象模型和业务层与代码背后的代码分离得非常好,那么您就在此转换中处于领先地位。不幸的是,这是一个非常难以简洁回答的问题,并且根据您当前的状态相当主观。

"Classic ASP.Net site" - weird to hear.

“经典的 ASP.Net 站点”- 听起来很奇怪。

回答by LBugnion

I think the question was wrongly worded, because this is not what I meant.

我认为这个问题措辞错误,因为这不是我的意思。

What I mean is: How can I integrateMVC-based pages in an existing "classic" ASP.NET site (yeah I know it sounds weird :)). I will eventually replace the whole content (and if it means rewriting some pages, so be it) but I want to already add new content based on MVC.

我的意思是:如何基于 MVC 的页面集成到现有的“经典”ASP.NET 站点中(是的,我知道这听起来很奇怪:))。我最终将替换整个内容(如果这意味着重写一些页面,就这样吧)但我想已经添加基于 MVC 的新内容。

I found guidance about how to create new MVC apps, and even how to integrate new web forms based content in it, but much less about porting an application to MVC gradually.

我找到了关于如何创建新的 MVC 应用程序,甚至如何在其中集成新的基于 Web 表单的内容的指南,但很少涉及将应用程序逐渐移植到 MVC。

I found this link http://blog.eworldui.net/post/2008/05/ASPNET-MVC---Living-in-a-Web-Forms-World.aspx

我找到了这个链接 http://blog.eworldui.net/post/2008/05/ASPNET-MVC---Living-in-a-Web-Forms-World.aspx

This is promising, but it sounds like a loooooooot of work.

这是有希望的,但听起来像是一项艰巨的工作。

Specifically, I am looking for steps to add new MVC based content in an existing ASP.NET application, and still keeping the old content to work like before.

具体来说,我正在寻找在现有 ASP.NET 应用程序中添加新的基于 MVC 的内容的步骤,并仍然保持旧内容像以前一样工作。