开发者

Routing webforms pages to a subfolder in a MVC3 application

I have a legacy ASP.Net Webforms site that I'm converting to MVC. The existing webform pages are in the root of the application (http://localhost/legacypage.aspx), but I want them to be in a 开发者_JAVA技巧/legacy/ folder in the MVC app so I don't have to see them in the visual studio solution all the time. However I don't want the legacy pages to have to include the subdirectory in the URL (http://localhost/legacy/legacypage.aspx), I want them to continue to be reachable from the original Url


You could do something like this in your global.asax:

  void Application_Start(object sender, EventArgs e)
  {
    RegisterRoutes(RouteTable.Routes);
  }

  void RegisterRoutes(RouteCollection routes)
  {
    routes.MapPageRoute(null, "{pagename}.aspx", "~/legacy/{pagename}.aspx");
  }

You may need also need another call to MapPageRoute for the / route because this will only fix /default.aspx route.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜