Fork me on GitHub

【记录】ASP.NET MVC MapRoute .htm 不起作用

RegisterRoutes 注册路由示例配置:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "default",
        url: "n/index_{id}.htm",
        defaults: new { controller = "Home", action = "Index" });
}

Controller 示例代码:

public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index(int id)
    {
        return View();
    }
}

测试环境是 ASP.NET MVC 5,如上配置,会抛出“404错误”,如果把 url 更改为:n/index_{id}.aspx,却是可以的,不知道具体是什么原因,解决方式是在 Web.config 中添加如下配置:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

参考问题:

posted @ 2014-12-15 13:39  田园里的蟋蟀  阅读(1840)  评论(2编辑  收藏  举报