码迷,mamicode.com
首页 > Web开发 > 详细

MVC 路由检测组件 Routing Debugger

时间:2014-12-10 15:51:54      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

组件下载地址 haacked.com

1、在mvc项目中引入组件

2、配置route规则

bubuko.com,布布扣
public static void RegisterRoutes(RouteCollection routes)
        {
            //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //忽略About页面,不能将它已到mapRoute后面,改方法不是有Route组件提供是System.Web.Mvc下的方法
            //routes.IgnoreRoute("Home/About");

            routes.MapRoute(
                "Default", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // 参数默认值
                new { controller=@"^\w+",action=@"^\w+"}
            );

            routes.MapRoute(
                "Filter", // 路由名称
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Filter", action = "Index", id = UrlParameter.Optional }, // 参数默认值
                new { controller = @"^\w+", action = @"^\w+" }
            );

            routes.MapRoute(
                "car",
                "Car/{make}/{pro}",
                new {controller="Car",action="Index",id=1}
                );

            routes.MapRoute(
                "Archive",
                "Archive/{date}",
                new { controller = "blog", action = "Archive" },
                new {date=@"^\d{4}-\d{2}-\d{2}" }

                );

            routes.MapRoute(
                    "Book",
                    "Book/Add/{name}",
                    new { controller = "Book", action = "Add" },
                    new { HttpMethod="Post"}
                );

            routes.MapRoute(
                "Product",
                "Product/{*value}",//*表示匹配一切内容
                new {controller="Product",action="Index" }
                );

            /*Dictionary<string, object> defaultRout = new Dictionary<string, object>();
            defaultRout["action"] = "Index";
            defaultRout["id"] = 0;

            RouteValueDictionary defaultRouteValue = new RouteValueDictionary(defaultRout);

            RouteValueDictionary constrainRouteValue = new RouteValueDictionary();
            constrainRouteValue["controller"] = @"\w+";
            constrainRouteValue["id"] = @"\d+";

            Route route = new Route("{controller}/{action}/{id}", defaultRouteValue, constrainRouteValue, new MvcRouteHandler());*/
        }
View Code

 

3、在Global.asax.cs代码中写入

   protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            //设为true表示url指向磁盘上的物理文件也会进行url routing处理,例如一个普通的html页面
            RouteTable.Routes.RouteExistingFiles = true;
            RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
            
        }

bubuko.com,布布扣

 

MVC 路由检测组件 Routing Debugger

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/ZJ199012/p/4155431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!