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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM