Giving route or Migrating ASP.net Web Form to ASP.

2019-09-16 07:31发布

问题:

I have a full web form application and want to migrate to MVC, before starting that I have been trying to implement The club site http://www.asp.net/downloads/starter-kits/extended-club using the instruction of Rob Conery, Scott Hanselman, Phil Haack in the book of Professional ASP.net MVC 2 in Chapter 12 . http://media.wiley.com/assets/1539/15/professionalaspnet35mvc_chapter13.pdf

I've created a folder for web form site, modified the Site.Master in shared folder using the web form master-page code and the result looks like:

According to the instructions I have to add routing to the site in Global.asax where I have tried many mapping route functions like:

  routes.MapRoute(
           "news", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "News", action = "Index", id = UrlParameter.Optional } // Parameter defaults
       );


        routes.MapPageRoute(
  "mvchome",
  "home/index/{id}",
  "~/ClubSite/News_List.aspx"
  );

But no changes. Have I missed something in before jumping to routes (Global.asax) or the solution is in giving the proper route or proper routes to all web forms pages?

回答1:

The first route matches ANY route, it is essentially a wildcard route. Place your other route BEFORE that route and it will be recognised.