从ASP.NET WebForms迁移到MVC

时间:2022-04-07 05:25:39

I've read plenty of questions and articles stating that converting from ASP.NET Webforms to MVC is near enough impossible. However I think my scenario is different.

我已经阅读了很多问题和文章,说明从ASP.NET Webforms转换到MVC几乎是不可能的。不过我认为我的情况有所不同。

I foolishly started working a project about a year ago in Webforms, but the approach I took (as far as I understand) is very MVC like. I have disabled forms validation, don't use any postbacks, use URL re-writing and all page changes are AJAX requests that load the page contents of ContentPlaceHolders (using a small hack, overriding the RenderControl method). I've also used my own ORM and RESTful Service API in seperate projects, referenced in the website.

我大约一年前在Webforms中愚蠢地开始创建一个项目,但我采用的方法(据我所知)非常像MVC。我已禁用表单验证,不使用任何回发,使用URL重写,所有页面更改都是加载ContentPlaceHolders页面内容的AJAX请求(使用小型hack,覆盖RenderControl方法)。我还在网站中引用的单独项目中使用了我自己的ORM和RESTful Service API。

Now the system works really well, the pages are partially refreshed fine and the url's are changed when the ajax calls are made, so when the page is refreshed, it looks exactly the same.

现在系统运行良好,页面部分刷新正常,并且在进行ajax调用时更改了url,因此当页面刷新时,它看起来完全相同。

Now I've just been told I need to learn MVC for a new big project (but I have to finish another project first), but I've done a bit of reading on the subject and started a few Hello World apps, and it seems that the idea of ASP.NET MVC is pretty much exactly what I have already created.

现在我刚刚被告知我需要为一个新的大项目学习MVC(但我必须先完成另一个项目),但我已经完成了一些关于这个主题的阅读,并启动了一些Hello World应用程序,它似乎ASP.NET MVC的想法几乎就是我已经创建的。

Would * still recommend against converting the Webforms application to MVC? Are there any other benefits of converting to MVC, besides best practices?

*仍然建议不要将Webforms应用程序转换为MVC吗?除了最佳实践之外,转换到MVC还有其他好处吗?

2 个解决方案

#1


3  

I have a very large and old ASP.NET WebForms application (which was originally written for .NET 1.1!) and have enabled MVC to work in it, side-by-side. I've been writing new features using MVC, and converting old WebForms features to MVC controllers and views.

我有一个非常大的旧的ASP.NET WebForms应用程序(最初是为.NET 1.1编写的!)并且已经使MVC能够并行工作。我一直在使用MVC编写新功能,并将旧的WebForms功能转换为MVC控制器和视图。

I ran into a few little issues concerning URL authorization and running in IIS integrated mode, but once I understood the issues they were fairly easy to work out. So nearly impossible? Certainly not!

我遇到了一些关于URL授权和在IIS集成模式下运行的小问题,但是一旦我理解了这些问题,它们就很容易解决了。那么几乎不可能?当然不是!

I can't tell you if it's worth your time to convert it, since I don't know the size, scope or nature of your application, or any business constraints. However, moving to MVC has been a considerable boon to ease of development and quality (since it is easier to compartmentalize and unit test). Not to mention, the features I've written (or rewritten) in MVC are much cleaner, faster, and responsive than the WebForms equivalents.

我无法告诉您是否值得花时间进行转换,因为我不知道您的应用程序的大小,范围或性质,或任何业务限制。然而,转向MVC对于简化开发和质量是一个相当大的好处(因为它更容易划分和单元测试)。更不用说,我在MVC中编写(或重写)的功能比WebForms等效功能更清晰,更快速,更快速。

I'm excited to move it from MVC v2 to v3, and convert to Razor views. So would I? I if I were you and I had the time, I'd do it.

我很高兴将它从MVC v2移到v3,并转换为Razor视图。我也会?如果我是你,我有时间,我会这样做。

Here's a question I posted that outlines the process and one of the more significant problems I had in the conversion. Migrating legacy ASP.NET to MVC 2 (RC): HttpApplication events not firing, User principal is null

这是我发布的一个问题,概述了流程以及我在转换过程中遇到的一个更重要的问题。将旧版ASP.NET迁移到MVC 2(RC):HttpApplication事件未触发,用户主体为空

#2


3  

I've recently converted a medium size project from WebForms to MVC. I would not recommend doing that on your first MVC project, but once you get the hang of it there really is nothing stopping you from (gradually) converting a WebForms app to MVC.

我最近将一个中等大小的项目从WebForms转换为MVC。我不建议你在你的第一个MVC项目中这样做,但是一旦你掌握了它,就没有什么能阻止你(逐渐)将WebForms应用程序转换为MVC。

One of the major benefits I've noticed is speed. By throwing out the viewstate, databinding and web control weirdness you'll end up with a much faster application.

我注意到的一个主要好处是速度。通过抛弃视图状态,数据绑定和Web控制怪异,您最终将获得更快的应用程序。

Of course there's also the better known benefits like testability and full control over the generated html.

当然,还有更好的已知好处,如可测试性和对生成的html的完全控制。

WebForms and MVC share the same basic ASP.NET platform, so they are really not as incompatible as you've read.

WebForms和MVC共享相同的基本ASP.NET平台,因此它们实际上并不像您读过的那样不兼容。

#1


3  

I have a very large and old ASP.NET WebForms application (which was originally written for .NET 1.1!) and have enabled MVC to work in it, side-by-side. I've been writing new features using MVC, and converting old WebForms features to MVC controllers and views.

我有一个非常大的旧的ASP.NET WebForms应用程序(最初是为.NET 1.1编写的!)并且已经使MVC能够并行工作。我一直在使用MVC编写新功能,并将旧的WebForms功能转换为MVC控制器和视图。

I ran into a few little issues concerning URL authorization and running in IIS integrated mode, but once I understood the issues they were fairly easy to work out. So nearly impossible? Certainly not!

我遇到了一些关于URL授权和在IIS集成模式下运行的小问题,但是一旦我理解了这些问题,它们就很容易解决了。那么几乎不可能?当然不是!

I can't tell you if it's worth your time to convert it, since I don't know the size, scope or nature of your application, or any business constraints. However, moving to MVC has been a considerable boon to ease of development and quality (since it is easier to compartmentalize and unit test). Not to mention, the features I've written (or rewritten) in MVC are much cleaner, faster, and responsive than the WebForms equivalents.

我无法告诉您是否值得花时间进行转换,因为我不知道您的应用程序的大小,范围或性质,或任何业务限制。然而,转向MVC对于简化开发和质量是一个相当大的好处(因为它更容易划分和单元测试)。更不用说,我在MVC中编写(或重写)的功能比WebForms等效功能更清晰,更快速,更快速。

I'm excited to move it from MVC v2 to v3, and convert to Razor views. So would I? I if I were you and I had the time, I'd do it.

我很高兴将它从MVC v2移到v3,并转换为Razor视图。我也会?如果我是你,我有时间,我会这样做。

Here's a question I posted that outlines the process and one of the more significant problems I had in the conversion. Migrating legacy ASP.NET to MVC 2 (RC): HttpApplication events not firing, User principal is null

这是我发布的一个问题,概述了流程以及我在转换过程中遇到的一个更重要的问题。将旧版ASP.NET迁移到MVC 2(RC):HttpApplication事件未触发,用户主体为空

#2


3  

I've recently converted a medium size project from WebForms to MVC. I would not recommend doing that on your first MVC project, but once you get the hang of it there really is nothing stopping you from (gradually) converting a WebForms app to MVC.

我最近将一个中等大小的项目从WebForms转换为MVC。我不建议你在你的第一个MVC项目中这样做,但是一旦你掌握了它,就没有什么能阻止你(逐渐)将WebForms应用程序转换为MVC。

One of the major benefits I've noticed is speed. By throwing out the viewstate, databinding and web control weirdness you'll end up with a much faster application.

我注意到的一个主要好处是速度。通过抛弃视图状态,数据绑定和Web控制怪异,您最终将获得更快的应用程序。

Of course there's also the better known benefits like testability and full control over the generated html.

当然,还有更好的已知好处,如可测试性和对生成的html的完全控制。

WebForms and MVC share the same basic ASP.NET platform, so they are really not as incompatible as you've read.

WebForms和MVC共享相同的基本ASP.NET平台,因此它们实际上并不像您读过的那样不兼容。