从 ASP.NET WebForms 迁移到 MVC [英] Migrating from ASP.NET WebForms to MVC

查看:27
本文介绍了从 ASP.NET WebForms 迁移到 MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过很多问题和文章,指出从 ASP.NET Webforms 转换到 MVC 几乎是不可能的.但是我认为我的情况是不同的.

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.

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

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.

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

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.

现在我刚刚被告知我需要为一个新的大项目学习 MVC(但我必须先完成另一个项目),但我已经阅读了一些关于该主题的内容并启动了一些 Hello World 应用程序,而且 ASP.NET MVC 的想法似乎与我已经创建的完全相同.

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.

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

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

推荐答案

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

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.

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

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!

我无法告诉您转换它是否值得,因为我不知道您的应用程序的大小、范围或性质,或者任何业务限制.然而,迁移到 MVC 对简化开发和质量来说是一个相当大的好处(因为它更容易划分和单元测试).更不用说,我在 MVC 中编写(或重写)的功能比 WebForms 等价物更干净、更快、响应更快.

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 v2 移动到 v3,并转换为 Razor 视图.我也会?如果我是你并且有时间,我会去做.

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.

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

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 WebForms 迁移到 MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆