• MVC 路由检测组件 Routing Debugger


    组件下载地址 haacked.com

    1、在mvc项目中引入组件

    2、配置route规则

    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);
                
            }

  • 相关阅读:
    我又来定计划了~2015-8至年底
    Spark官方文档中推荐的硬件配置
    java 多线程之:sleep() 方法
    Referrer Policy 介绍
    js 操作 cookie
    顶级域名和子级域名之间的cookie共享和相互修改、删除
    关于 Cookie-free Domains (为什么将静态图片,js,css存放到单独的域名?)
    cookie 知识点
    java 多线程之:yield() 方法
    java 多线程之:wait()、notify()、notifyAll()等方法
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/4155431.html
Copyright © 2020-2023  润新知