0

The current codebase at work is entirely WebForms, with most logic being stuffed into the code-behind file. I'm investigating the possibility of using MVC3 for new pages added and future refactoring without having to throw the entire codebase away (a big no-no). All of these pages are part of the same "application" so it's not as simple as just creating new projects with MVC - they have to interact very closely, and in some cases WebForms pages will have to redirect to MVC pages, and vice versa.

I've come across a few articles that show how it's possible to integrate the two (albeit in very simple scenarios, while my scenario is fairly complex), but are there any issues to be aware of? Specifically in regards to going from a WebForms page to an MVC page and then back to a WebForms page, where data is required to be passed across pages say from the Session (and not necessarily read entirely from a database upon load), for example a workflow like:

  1. (WebForms) User goes to CreateQuote.aspx?CustomerId=42 and enters some data. They click a "Process" button...
  2. (MVC) /customers/42/process MVC page that reads in the information submitted before, and does some extra things. User hits a "Next" button...
  3. (WebForms) CompleteQuote.aspx?CustomerId=42&QuoteId=534235 page that pulls out information from the previous MVC page and applies more logic to it.

Also, our existing project is an ASP.NET Web Site project (i.e. the one where every individual page is its own DLL); would it have to be converted to a Web Application project to exist side by side with MVC (that alone is a major refactoring effort due to large clumps of duplicate code across code-behind files)?

Wayne Molina
  • 19,158
  • 26
  • 98
  • 163
  • 1
    Possible duplicate of: - http://stackoverflow.com/questions/7288840/asp-net-mvc-alongside-web-forms-in-the-same-web-app - http://stackoverflow.com/questions/7288840/asp-net-mvc-alongside-web-forms-in-the-same-web-app – maxbeaudoin Feb 20 '12 at 16:32

1 Answers1

2

I would recommend you to avoid mixing ASP.NET MVC and classic WebForms in the same application. Keep them in separate projects and make them communicate through standard HTTP protocol mechanisms (query string parameters, form posts, cookies, ...). You could share authentication between them if they are hosted on the same domain. You could even share session objects between them even if they are hosted in separate application pools in IIS (not that you should be using session at all, but that's another topic).

As far as reusing the data access logic is concerned, well, depending on how properly your existing WebForms application is designed, you could share the assembly that contains your current data access code. And if your existing application is poorly designed with strong coupling between the different layers, you could wrap this legacy code behind a repository and still reuse at least the database access code.

By keeping your applications separate you don't need to pollute your new ASP.NET MVC application with references to some legacy code and you don't need to pollute your existing application classic WebForms application with ASP.NET MVC specific things.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • +1 there is inherently no difference between site.com/action and sub.site.com/action other than url handling is slightly more complicated and obviously the need for separate hosting (which arguably could just be a virtual directory inside the original site root). – Chris Marisic Feb 21 '12 at 13:49
  • Thanks, that's what I was afraid of. The current WebForms incarnation is **very** poorly done -thousand line code-behind files, duplicate logic everywhere, but we can't scrap it due to all the investment over the years, so the only option would be to run them side by side except the MVC app isn't a real app just specific pages; as I said they are all one single application, so it's not like Project A in WebForms talks to Project B in MVC, it's more like Page A in WebForms would have to talk to Page B in MVC. Sadly this sounds like it's near impossible to do without tons of refactoring. – Wayne Molina Feb 21 '12 at 14:25