mvc 伪静态任意扩展名的实现方法

比如:要实现 http://localhost:60291/home/geta/1212.html 或者 .abc 任意扩展名

 

完成两步即可。

第一步修改路由:

   public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                 name: "2",
                 url: "{controller}/{action}/{id}.html",
                 defaults: new { controller = "Home", action = "Index",  }
             );
            
        }

第二步:修改web.config

增加

<system.webServer>节点 增加如下:
    <modules runAllManagedModulesForAllRequests="true"></modules>

posted @ 2016-08-02 22:45  IDOER  阅读(748)  评论(9编辑  收藏  举报