Reputation: 36034
Currently I'm working on Web project that is built using ASP.NET Web Forms. We want to start building new pages using MVC framework.
Looks like running MVC and Web Forms side by side is doable Running ASP.NET Webforms and ASP.NET MVC side by side
I'm curious if there are any problems or gotchas that I need to plan for.
I'm running on ASP.NET 4.0 and planning to use MVC3.
Upvotes: 11
Views: 7461
Reputation: 5471
I suggest keeping the two applications separate and give them different subdomains, you might be able to keep them on the same subdomain by using a virtual directory, but I didn't like that approach.
You can use a single cookie to validate on both apps by sharing the validationKey and decryptionKey.
This way your code bases don't mix and you are not fighting any configuration file issues.
I've posted a longer description of this approach.
Upvotes: 0
Reputation: 20246
In addition to what Darin said, try to not use the WebForms view engine if you can help it and create proper URL routes so that pages that should be handled by WebForms are still handled by WebForms.
Upvotes: 2
Reputation: 27803
I have been running Webforms and MVC together for an internal application here. It started off as a webforms application and I have migrated it into MVC2 (then 3) with several pieces still successfully working with Webforms still.
As Darin said, the main gotcha is going to be with templating. If you use the Webforms View Engine you have to create 2 layers of master pages. Webforms code (such as the script manager) do not run on MVC pages, and MVC code doesn't work under Webforms pages.
My master pages are setup with a global master page that doesn't contain any MVC or Webforms code. It only has CSS, global javascript, and main layout. I then have a MVC master page and a webforms master page, both have directives to use the global master page as their master pages. Then each webforms page uses the Webforms sub-master page and the MVC uses the MVC sub-master page.
If you need to put some code in the global master page, you can detect if the sub-page is a Webforms or MVC page by testing if Page is System.Web.Mvc.ViewPage
. If that's true
then it's an MVC page, otherwise it is a Webforms page.
However, if you decide to go with the Razor view engine (which I do recommend for MVC, it's so much better) it becomes harder. You have to do some additional work arounds past what I previously mentioned. This blog post should help in that regards.
Upvotes: 11
Reputation: 1778
I guess it depends on what interaction there will be between the WebForms and the MVC parts of the site. If both are using the same back-end and same security log in then you should be OK. You might experience problems if a web-form and an MVC action need to co-operate. As I say it really all depends on what the interaction will be. If they are running side-by-side but leaving each other alone, then you should be fine.
One problem that might occur is the shift in thinking that is needed to switch from WebForms to MVC and vice-versa, although experience and practice will teach you here.
Upvotes: 1
Reputation: 1038710
The only gotcha I can think of is to be tempted of reusing existing WebForms code into the MVC part and end up with DataSets
into your controller action, or (may God forbid) into your views :-) Another gotcha with reusing such code is that you should be very careful not to end up with runat="server"
stuff into your MVC views. I would keep the two parts as loosely coupled as possible. And because of that I wouldn't mix them into the same project :-)
Upvotes: 1