Has anyone successfully deployed ASP.NET MVC alongside Web Forms in the same application in a production environment? Were there any conflicts or gotchas you faced while doing so?
Is it really as easy as shown here in practice? What about if you run a MVC using the Razor view engine alongside Web Forms?
Mvc is build on top of asp.net as is webforms, so yes it's easy.
Done it couple of times for conversion purposes
Maybe this url's could help you:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
and
http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx
One gotcha is don't put your WebForms
inside the Views folder. I haven't get figured how to make MVC
leave those paths alone. None of the ignore routing instructions seems to work in this case and the WebForms
throw 404s.
Other than that WebForms
works perfectly fine alongside MVC
since MVC2
.
Has anyone successfully deployed ASP.NET MVC alongside Web Forms in
the same application in a production environment?
I never mixed ASP.NET MVC and classic WebForms in the same application. I make them run in separate applications and communicate between them with standard HTTP techniques (query string parameters, form posts, cookies, ...).
Is it really as easy as shown here in practice?
Yes, it is as easy as that.
Check out scott hanselmans AddMvc3ToWebForms nuget package. I am using it and its working pretty great. I am using it to gradually convert my web forms app to mvc
I've spent a lot of time over the past few months on this. Here are my observations.
The good/easy
- Getting Webforms
to call into MVC
controllers
- It was remarkably easy to stand up a new MVC3
project and drop Webforms
pages into it.
- I was able to move my <pages><controls></controls></pages>
section into the /pages
directory in a new web.config
there
The dirty/difficult
this is what I did to address that
@if (System.Diagnostics.Debugger.IsAttached)
{
<script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> @* intellisense! *@
@Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
@Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
}
else
{
@Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js)
@Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)
}
Recommendations:
- Use
T4MVC
in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js
,.css
, images, specifying templates) is outstanding.
- and if you have any part of your build process compiling views then you get compile-time safety on any of those links.