MVC小系列(二十一)【带扩展名的路由可能失效】
mvc3之后:如果路由带上扩展名,比如这样:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("favicon.ico"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //register custom routes (plugins, etc) var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); routePublisher.RegisterRoutes(routes); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}.html", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "MyMvc.Web.Controllers" } ); }
在浏览器输入: http://localhost:15526/Home/Index.html
可能会报错:404错误,
解决方法:把这玩意设置成:
<modules runAllManagedModulesForAllRequests="true"> <!-- <remove name="UrlRoutingModule-4.0" /> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />--> </modules>