Provides a collection of routes for ASP.NET routing.

The RouteCollection class provides methods that enable you to manage a collection of objects that derive from the RouteBase class.

这个类相对而言比较复杂了。支持很多方法和属性,以及扩展方法。下面会记录一些我用过的方法。

在asp.net app中, 启动文件一般会写成这样:

这里我们看到红圈中标识的就是route collection。

    /// <summary>Ignores the specified URL route for the given list of available routes.</summary>
/// <param name="routes">A collection of routes for the application.</param>
/// <param name="url">The URL pattern for the route to ignore.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="routes" /> or <paramref name="url" /> parameter is null.</exception>
public static void IgnoreRoute(this RouteCollection routes, string url); /// <summary>Maps the specified URL route.</summary>
/// <returns>A reference to the mapped route.</returns>
/// <param name="routes">A collection of routes for the application.</param>
/// <param name="name">The name of the route to map.</param>
/// <param name="url">The URL pattern for the route.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="routes" /> or <paramref name="url" /> parameter is null.</exception>
public static Route MapRoute(this RouteCollection routes, string name, string url);

MapRoute是最为常用的一种配置route的方式, 它同时有多中重载形式可以根据不同的情况进行使用。

    /// <summary>Provides a way to define routes for Web Forms applications.</summary>
/// <returns>The route that is added to the route collection.</returns>
/// <param name="routeName">The name of the route.</param>
/// <param name="routeUrl">The URL pattern for the route.</param>
/// <param name="physicalFile">The physical URL for the route.</param>
/// <param name="checkPhysicalUrlAccess">A value that indicates whether ASP.NET should validate that the user has authority to access the physical URL (the route URL is always checked). This parameter sets the <see cref="P:System.Web.Routing.PageRouteHandler.CheckPhysicalUrlAccess" /> property.</param>
/// <param name="defaults">Default values for the route.</param>
/// <param name="constraints">Constraints that a URL request must meet in order to be processed as this route.</param>
public Route MapPageRoute(string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, RouteValueDictionary defaults, RouteValueDictionary constraints);

MapPageRoute据说是asp.net web form中的route方式,但是也有和MVC混合使用的。这种MapRoute以及MapPageRoute混合使用会造成route conflict, 导致app中使用的Html.Action这种寻找Action的方式失效。效果就是actiion本身访问的action的URL却指向到MapPageRoute指定的URL当中去。 该问题目前我是通过调整route注册顺序以及加入一些约束, 比如Regex去解决的。

——————————————————————————————————————————————————————————————————————————————

Reference:https://docs.microsoft.com/en-us/dotnet/api/system.web.routing.routecollection?view=netframework-4.7.2

【ASP.NET】System.Web.Routing - RouteCollection Class的更多相关文章

  1. 【ASP.NET】System.Web.Routing - HttpMethodConstraint Class

    你可以自己定义你的ASP.NET程序接收的get post put 或者delete请求. 使用这个约束的方式为: void Application_Start(object sender, Even ...

  2. 【ASP.NET】System.Web.Routing - PageRouteHandler Class

    用于提供一些属性和方法来定义如何将URL匹配到一个物理文件上面. public PageRouteHandler (string virtualPath, bool checkPhysicalUrlA ...

  3. 【ASP.NET】System.Web.Routing - StopRoutingHandler Class

    Provides a way to specify that ASP.NET routing should not handle requests for a URL pattern. ex: rou ...

  4. 【ASP.NET】System.Web.Routing - Route Class

    Provides properties and methods for defining a route and for obtaining information about the route. ...

  5. ASP.net 的URL路由选择(System.Web.Routing.dll)

    System.Web.Routing是.net 3.5sp1中新增的一个dll,用它提拱的类可以很方便的实现url的映射,在asp.net WebFrom的编程中可以使客户端请求的URL变得更加的&q ...

  6. 返璞归真 asp.net mvc (2) - 路由(System.Web.Routing)

    原文:返璞归真 asp.net mvc (2) - 路由(System.Web.Routing) [索引页] [源码下载] 返璞归真 asp.net mvc (2) - 路由(System.Web.R ...

  7. 【ASP.NET】UCenter实现多站点同步登录退出

    利用UCenter实现discuz论坛和应用网站同步登录和退出功能 测试环境:Discuz! X3.2.UCenter 1.6..Net Framework 4.0 进入Discuz 后台的UCent ...

  8. System.Web.Routing入门及进阶 上篇

    System.Web.Routing已经作为一个程序集包含在.net3.5sp1中发布了.虽然我们并没有在3.5sp1中发现Asp.net Mvc的踪迹,但是亦以感觉到它离我们不远了. System. ...

  9. 【ASP.NET】第一个ASP.NET MVC应用程序

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 开发流程 新建Controller 创建Action 根据Action创建View 在Action获取数据并生产ActionResult传递 ...

随机推荐

  1. 使用函数接口和枚举实现配置式编程(Java与Scala实现)

    概述 做报表时,有时需要根据不同的业务生成不同的报表.这样,需要能够动态地配置列字段,并根据列字段来输出对应的报表.使用函数接口结合枚举可以比较优雅地实现配置式编程. 问题描述如下: 假设有对象 St ...

  2. create-react-app @observer装饰器报错

    npm install --save-dev babel-plugin-transform-decorators-legacy 然后在node_modules/babel-preset-react-a ...

  3. 远程服务调用RPC框架介绍,微服务架构介绍和RPC框架对比,dubbo、SpringClound对比

    远程服务调用RPC框架介绍,微服务架构介绍和RPC框架对比,dubbo.SpringClound对比 远程服务调用RPC框架介绍,RPC简单的来说就是像调用本地服务一样调用远程服务. 分布式RPC需要 ...

  4. [转载]tnsnames.ora监听配置文件详解

    监听配置文件             为了使得外部进程 如 CAMS后台程序 能够访问 Oracle 数据库 必须配             置 Oracle 网络服务器环境 配置 Oracle 网络 ...

  5. 设置PyCharm创建文件时自动添加头文件

    找到该路径并添加以下信息 File->settings->Editor->File and Code Templates->Python Script  #!/usr/bin/ ...

  6. 自学Java第七周的总结

    这一周里我将看过的知识点又复习了一遍,下个星期打算将题做一遍

  7. Django框架----Form组件

    Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...

  8. linux系统Centos环境下搭建SVN服务器及权限配置

    linux系统Centos环境下如何搭建SVN服务器以及svnserve.conf.authz.passwd配置文件详细介绍   至于svn的概念,这里就不做详细阐述了,可以自行百度.简单来讲就是一个 ...

  9. GoldenGate实时投递数据到大数据平台(3)- Apache Flume

    Apache Flume Flume NG是一个分布式.可靠.可用的系统,它能够将不同数据源的海量日志数据进行高效收集.聚合,最后存储到一个中心化数据存储系统中,方便进行数据分析.事实上flume也可 ...

  10. ES6知识整理(9)--class的基本语法

    (总结完知识点,出去滑板刷街) promise的catch 上一节promise中漏了一个知识点: promise对象可以使用catch来避免每个then中都加error判断,让错误时都进到catch ...