将webforms页面路由到MVC3应用程序中的子文件夹

时间:2011-05-17 22:55:43

标签: asp.net asp.net-mvc iis-7 routing webforms

我有一个传统的ASP.Net Webforms网站,我正在转换为MVC。现有的webform页面位于应用程序的根目录中(http://localhost/legacypage.aspx),但我希望它们位于MVC应用程序的/ legacy /文件夹中,因此我不必在视觉工作室解决方案始终如一。但是我不希望遗留页面必须包含URL中的子目录(http://localhost/legacy/legacypage.aspx),我希望它们可以继续从原始URL访问

1 个答案:

答案 0 :(得分:6)

你可以在global.asax中执行类似的操作:

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

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

您可能还需要另外调用MapPageRoute作为/ route,因为这只会修复/default.aspx路由。