【问题标题】:ASP.NET MVC URL Routing or URL rewritingASP.NET MVC URL 路由或 URL 重写
【发布时间】:2013-01-19 07:31:14
【问题描述】:

我是 ASP.NET MVC 的新手,正在尝试确定以下任务的最佳方法。我有以下从 Web 窗体应用程序继承的 URL,我想通过在 MVC 中返回以下路径来继续运行:

  1. http://example.com/Default.aspx -> http://example.com/
  2. http://example.com/about.aspx -> http://example.com/about
  3. http://example.com/keyword1-keyword2-contact.aspx -> http://example.com/contact

我应该创建一个新的地图路线还是使用 URL 重写模块?请举例说明您提倡的方法。该应用程序托管在 IIS 7.5 中,并使用 ASP.NET 4.5 和 MVC 4.0。

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-4


【解决方案1】:

我也是新手,但我会尽力帮助你。

在 App_Start/RouteConfig.cs 中

1

routes.MapRoute(
   null,
   "Default.aspx",
   defaults: new { controller = "Default", action = "Index"},
);

2

routes.MapRoute(
   null,
   "about.aspx",
   defaults: new { controller = "Default", action = "About"},
);

3

routes.MapRoute(
   null,
   "{keyword1}-{keyword2}-contact.aspx",
   defaults: new { controller = "Default", action = "Contact"},
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-23
    • 2011-11-11
    • 2010-11-21
    • 2010-11-22
    • 2010-11-13
    相关资源
    最近更新 更多