ASP.NET MVC4实现URL伪静态
1.在Web.config添加节点配置:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"></modules> </system.webServer>
2.修改RouteConfig:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//路由匹配右上往下,优先匹配的放上面。 routes.MapRoute( name: "Phone", url: "Phone/{pre}_{mid}.html", defaults: new { controller = "Phone", action = "PreList", pre = UrlParameter.Optional, mid = UrlParameter.Optional } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}",UrlParameter.Optional } defaults: new { controller = "Phone", action = "Index", id = UrlParameter.Optional } ); }
3.访问:
http://localhost:50820/Phone/134_0000.html
路由结果为:Phone/PreList?pre=134&mid=0000
参考来源:ASP.NET MVC5 实现网址伪静态