Mvc自定义路由让支持.html的格式

前言

在大多时候,我们都需要自定义路由,当我们设置为/list/1.html的时候,有的时候会出现以下异常。

            routes.MapRoute(
                "category", // 路由名称
                "list/{cid}.html", 
                new { controller = "Category", action = "Category" } 
            );

  

为什么会这样那,非常纠结,如果你把路由中的.html去掉访问,http://localhost:5729/list/13  完全可以打开页面。怎么办?

解决办法

Config 中<system.webServer>  添加节点代码

<modules runAllManagedModulesForAllRequests="true"></modules>

  这样就能解决后缀为.html 或其他后缀的问题

原文地址:https://www.cnblogs.com/searchbaidu/p/5857522.html