mvc中让路由忽略带后缀的路径文件

 1 public static void RegisterRoutes(RouteCollection routes)
 2 {
 3 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 4 routes.Ignore("{*allfiles}", new { allfiles = @".*\.(.*)(/.*)?" });
 5 //routes.MapRoute(
 6 // name: "Default",
 7 // url: "{controller}/{action}/{id}",
 8 // defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
 9 //);
10 
11 routes.MapRoute(
12 "Default", // Route name
13 "{controller}/{action}/{id}", // URL with parameters
14 new { controller = "Home", action = "Index", id = UrlParameter.Optional },
15 new string[] { "WebApplication1.Controllers" } // Parameter defaults // Parameter defaults
16 );
17 }

比如在mvc中使用webService 如果不添加routes.Ignore("{*allfiles}", new { allfiles = @".*\.(.*)(/.*)?" });你是无法访问调用webservice中的方法的

 
posted on 2013-11-07 09:48  sunashang  阅读(594)  评论(0编辑  收藏  举报