4

I've searched the archives and also googled about it but it seems I can't find a guide / best practices / how-to on how to smoothly add features to an existing ASP.net 4 website, adding them in the latest MVC. I have a website that was built with ASP.net 1.0 and progressively has been upgraded to 4.0, now I want to switch to MVC but re-create all the website in MVC is a too long process since the site has a lot of features, and some parts are just good in webforms. The best way for me should be to be able to smoothly add MVC to this existing ASP.net 4.0 website and progressively migrate the existing webforms to MVC.

(Don't want to start a webforms-MVC flame, just looking on some tips on how to avoid common mistakes.)

1 Answer 1

2
  1. add System.Web.Mvc reference in ASP.net website
  2. for support MapRoute,you need add the following code in web.config:

<system.webServer>
 <validation validateIntegratedModeConfiguration="false"/>
 <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

 3. add assembly reference in web.config:


<compilation defaultLanguage="c#" debug="false" targetFramework="4.0">
    <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>
</compilation>
4. add routes map in Global.asax,such as:


public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );
}

protected void Application_Start()
{
    RegisterRoutes(RouteTable.Routes);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @artwl, thank you very much for the answer. Seems very (too) easy, is it everything needed? And the MVC folder structure etc? I was thinking to create a new MVC project and copy some structure from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.