Migrating from ASP.NET WebForms to 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.

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.

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.

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.

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

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!

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.

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.

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

Method 2

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.

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.

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

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x