首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

MVC3路由器解决办法

2012-03-18 
MVC3路由器C# codepublic static void RegisterRoutes(RouteCollection routes){routes.IgnoreRoute({res

MVC3路由器

C# code
   public static void RegisterRoutes(RouteCollection routes)        {            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");            List<string> language = Common.XMLHelper.GetValueAll_();            foreach (string str in language)            {                routes.MapRoute(Guid.NewGuid().ToString().Substring(0, 5), "{languages}", new { controller = "Book", action = "Index", languages = str });            }            routes.MapRoute(                "Default", // 路由名称                "{controller}/{action}/{id}", // 带有参数的 URL                new { controller = "Book", action = "Index", id = UrlParameter.Optional } // 参数默认值            );        }

请教路由规则问题List<string> 是一个类似en-us、zh-cn的泛型集合,为什么我在浏览器里面输入www.123.com/zh-cnnnnnn也能进入到Action里面呢?

[解决办法]
routes.MapRoute(Guid.NewGuid().ToString().Substring(0, 5), "{languages}", new { controller = "Book", action = "Index", languages = str });
这样只是指定languages的缺省值,如果希望只允许en-us, zh-cn,用这个试试:

routes.MapRoute(Guid.NewGuid().ToString().Substring(0, 5), str , new { controller = "Book", action = "Index"});

热点排行