Make MVC URL same as old ASP.Net website -


i have website developed in dot net 2.0 need update in mvc framework. how keep old urls same in mvc? eg. www.something.com/home.aspx , www.something.com/about.aspx. need keep url structure. please help.

use mvc routing make urls same old site.

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      routes.maproute(         name: "home",         url: "home.aspx",         defaults: new { controller = "home", action = "index" }     );      routes.maproute(         name: "about",         url: "about.aspx",         defaults: new { controller = "home", action = "about" }     );      routes.maproute(         name: "default",         url: "{controller}/{action}/{id}",         defaults: new { controller = "home", action = "index", id = urlparameter.optional }     ); } 

note in mvc 5 use attribute routing alternative putting every route in shared registerroutes method.

public static void registerroutes(routecollection routes) {     routes.ignoreroute("{resource}.axd/{*pathinfo}");      // important: put before default route     // or attribute routing won't work.     routes.mapmvcattributeroutes();      routes.maproute(         name: "default",         url: "{controller}/{action}/{id}",         defaults: new { controller = "home", action = "index", id = urlparameter.optional }     ); }  public class homecontroller : controller {     [route("home.aspx", name = "home")]     public actionresult index()     {         return view();     }      [route("about.aspx", name = "about")]     public actionresult about()     {         viewbag.message = "your application description page.";          return view();     } } 

another alternative use new url scheme , use iis rewrite module configure 301 redirects old url locations new ones don't lose traffic , of old hyperlinks still work.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -