`

5.3使用Routes

阅读更多
5.3使用Routes

注册Area Route
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            AreaRegistration.RegisterAllAreas();
            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional });

        }

AreaRoute冲突
如何处理冲突
抛出异常
处理方法,使用NameSpace
route.MapRoute{
“Default”,
“{controller}/{action}/{id}”,
new {controller=“Home”,action=“Index”,id=“”),
new [] {“AreaDemoWeb.Controllers”}
}

捕获所有参数
让Route匹配任意多参数

routes.MapRoute(“catchallroute”,”query/{query-name}/{*extrastuff}”,
new QueryRouteHandler));


URL                   *extrastuff   
/query/select/a/b/c “a/b/c”   
/query/select/a/b/c/ “a/b/c”   
/query/select          “”(route仍然可以匹配)

全部匹配到一个参数上

停止匹配和忽略匹配
Route.add(new Route("{resource}.axd/{*pathinfo}",
new StopRoutingHandler())};

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

调试路由信息
使用 Routing Debugger

http://cde.hacked.com/mvc-1.0/RouteDebug-binary.zip

Protected void Application_Start(){
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}

分享到:
评论

相关推荐

    Test-Drive ASP.NET MVC

    5.3 Testing Routes in MVC 5.4 Storing Information in Memory 5.5 Manipulating Files 6 Enhancing Views with HTML Helpers and Master Pages 6.1 Making Our Site Presentable with HTML Helpers 6.2 ...

    Laravel5.3+框架定义API路径取消CSRF保护方法详解

    从Laravel 5.3+开始,API路径被放入了routes/api.php中。我们绝大多数的路径其实都会在web.php中定义,因为在web.php中定义的路径默认有CSRF保护,而API路径默认没有CSRF保护。在Laravel官网文档中写到:/p> Any ...

    lily:适用于PHP 5.3+的轻量级Web应用程序库

    // Lily provides building blocks for applications like routing$ handler = new Lily \ Application \ RoutedApplication ([ // Define your routes as plain arrays 'routes' => [[ 'GET' , '/' , 'Hello world'

    Web前端框架应用:第5章 Vue路由-嵌套路由.pptx

    嵌套子路由的关键属性是children,children也是一组路由,相当于前面讲到的routes,children可以像routes一样的去配置路由数组。每一个子路由里面可以嵌套多个组件,子组件又有路由导航和路由容器。 父路由的地址/要...

    修改Laravel5.3中的路由文件与路径

    前言 大家可能没有注意到, 在 Laravel 4 以及更老版本中, 路由逻辑是性能上的一个瓶颈–特别是对于有很多路由...在 Laravel 5.2 的routes.php中我们可以看到路由被分割成两个路由群组:web和api,这样做的原因是基于

    Web前端框架应用:第5章 Vue路由-命名路由.pptx

    通过一个名称来标识一个路由显得更方便一些,特别是在链接一个路由,或者是执行一些跳转的时候,通过路由的名称取代路径地址直接使用。像这种命名路由的方式,无论path多长、多烦琐,都能直接通过name来引用,十分...

    codeigniter-static-laravel-routes:集成类似laravel的静态路由并过滤到codeigniter 3.x和2.x中

    5.3或以上 发牌 目前,我没有许可该作品。 它具有Bonfire项目的一些代码,并保留了其许可权。 未来的计划 缓存路线。 安装 只需使用相同的文件夹结构将文件复制到您的服务器即可。 如果开发人员以前安装了作为HMVC...

    JavaScript Applications with Node.js, React, React Native and MongoDB

    5.3 Sharding Chapter 6: NewsWatcher App Development 6.1 Create the Database and Collection 6.2 Data Model Document Design 6.3Trving Out Some Queries 5.4Indexing Policy 6.5Moving On Chapter 7: DevOps ...

    vrata:用PHP和Lumen实现的API网关

    概述Vrata(俄语为“ gates”)是使用Lumen框架在PHP7中实现的简单API网关介绍性博客文章,要求和依赖性PHP> = 7.0 流明5.3 食尸鬼6 Laravel护照(与) Memcached(用于请求限制)作为Docker容器运行理想情况下,您...

    vmware-r-vsan-tm-network-design.pdf

    Fault Domains Statements 1.6.Layer-2 and Layer-3 Support Statements 1.7.Multicast 1.8.Unicast 1.9.Jumbo Frames 1.10.IPv6 support 1.11.TCP/IP Stacks 1.12.Static Routes 1.13.NSX 1.14.Flow Control 1.15....

    understanding linux network internals

    Section 5.3. Basic Goals of NIC Initialization NIC初始化的基本目标 Section 5.4. Interaction Between Devices and Kernel 设备与内核的交互 Section 5.5. Initialization Options 初始化选项 Section 5.6. ...

Global site tag (gtag.js) - Google Analytics