I had a pretty big ASP.NET web site (not a web application) and wanted to add MVC3 to it. I had no option to change the type of the project so I had to go with the web site (asp.net 4.0).
I use a separate MVC project but not as it's own web application but as an assembly within my old web site.
Here's a rundown of what I did:
In Application_Start we need:
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
Then add the usual routing methods:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// your routes
}
Next add a few things to the web.config of your web site. In system.web under compilation we need the following assemblies:
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
Initially I also added some MVC namespace to web.config but it seems to work fine without them.
You do now create new routes in Global.asax of the web site, then add a corresponding controller in the MVC project and then back to the web site to add a view for it.
So you logic is all in a assembly while the views and the routing is defined in the web site.
You can still debug into the MVC controllers by setting break points there, but you debug by starting the web site.
If you use the suggested default route of MVC:
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
a call to www.mysite.com will serve up the content of the home controller/view not your old
default.aspx home page, so I just don't use such a route. If you routes conflict with existing physical folders and files, use constraints with regular expressions on the routes to exclude such conflicts.
Even though I use master pages in the web site, the actual html for the common page parts is created by code in another assembly. I could just call the same methods from my _ViewStart.cshtml or my base controller.
So far I have not seen any real negative about this approach.