Add MVC to existing ASP.net website

I searched the archives as well as searched for it, but it seems I can't find a guide / best practices / instructions on how to smoothly add features to an existing ASP.net 4 website, adding them to the latest MVC. I have a website that was created with ASP.net 1.0 and was gradually upgraded to 4.0, now I want to switch to MVC, but re-creating the whole website in MVC is too long, because the site has many functions, and some parts are just good at web forms. The best way for me is to be able to smoothly add MVC to this existing ASP.net 4.0 website and gradually migrate existing web forms to MVC.

(You don't want to fire the webforms-MVC flames just by looking at some tips on how to avoid common errors.)

+4
source share
1 answer
  • Add the System.Web.Mvc link to the ASP.net website.
  • To support MapRoute, you need to add the following code to web.config:
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> 

3. Add a link to the assembly 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); } 
+2
source

Source: https://habr.com/ru/post/1386787/


All Articles