Adding MVC to a ASP.NET Website

I've successfully added a ASP.NET MVC 3 to Webforms project and here are some suggestions:

  • Add Controllers as a separate class library project and add a reference to this project from the Web forms web project
  • I attempted to get VS MVC support (like goto controller etc), but adding the GUID {E53F8FEA-EAE0-44A6-8774-FFD645390401} to the .csproj file didn't help.
  • Yes, you can add references to get the Session from your class library. You can always mock it out if you want to write unit tests.
  • Add Views folder to the root
  • Add Models within App_Code
  • If you are using Razor, then you need to add System.Web.Razor and System.Web.WebPages references
  • If you are using Razor, update the Web.config per this post
  • Keep in mind, you can add server controls to your view as long as they don't use postbacks (I had a lot of server controls from my webforms project that I had to use)

I believe if you set up a new MVC project and copy your web forms across to the new project, they will render as expected.

I haven't experimented with this too much but I have tried in the past out of curiosity and the web forms were still rendered OK. I guess it depends on the complexity of your project as to whether this approach would work.

This would involve changing your project type.


With asp.net MVC2 and above, the MVC team separated the core functionality into three different assemblies, each of which extends from the common System.Web assembly:

  • System.Web.Routing
  • System.Web.Abstractions
  • System.Web.Mvc

With this seperation, they went ahead and made the assemblies to "work in Medium-trust server enviroments and be bin-deployable".

One of the good things about this featuere is, you don't have to have a specific project type to run MVC. You only need the assemblies, some directories and a tweaked web.config.

To do this, you need only to place the assemblies in your local bin folder of your project and make the necessary references for those assemblies. Once this is done, you have access to asp.net MVC.

Here are some detailed instructions from the Wrox Professional ASP.NET MVC 1.0 book which should help you get started:

Including MVC in Existing Web Forms Applications

Adding ASP.NET MVC functionality to an existing Web Forms application is comprised of three different steps:

1. Add a reference to the three core libraries that ASP.NET MVC needs: System.Web.Mvc, System.Web.Routing, and System.Web.Abstractions.

2. Add two directories to your application: Controllers and Views.

3. Update the Web.config to load the three assemblies at run time as well as registering the UrlRoutingModule HttpModule.

For reference, here are a couple of blogs/sites which have some more detailed scenarios which might help you out:

Mixing ASP.NET Webforms and ASP.NET MVC

ASP.NET WebForms and ASP.NET MVC in Harmony

Good luck, and hope this helps you out some.