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. Teacher Bo (时间复杂度 + 暴力)

    如果你仔细看就会发现有一个数据很重要那就是点的范围,那么这样一来最多只有2 * maxn的不同曼哈顿距离了,这样一看只要暴力一下就可以过了. #include<bits/stdc++.h> ...

  2. ODBC数据库

    ODBC数据源全称是开放数据库互连(Open Database Connectivity),在微软公司开放的数据库结构中的一部分,其实是一个应用程序的接口,主要用于提供数据库的编写应用程序的能力.

  3. loadRunner手动关联,通过 web_reg_save_param()函数

    Action() { //<B>sign up now</B></A>      /*     web_reg_save_param_regexp(         ...

  4. px-pt-dp-rem像素单位的换算问题

    px-pt-dp-rem像素单位的换算问题 dp 的意思从 MDPI 到 XXXHDPI 每单位物理尺寸的像素数越来越大.也就是说 mdpi 时 1dp = 1pxxxxhdpi 时 1dp = 4p ...

  5. 2017年3月29日 webService入门理解 二

    前边说到了N多webService的概念. 其实,说白了,我个人理解的话,webService就是一个“概念”.就好像互联网一样,就是一个很虚幻,很高的一个概念.同样,webService也是.互联网 ...

  6. 算法提高 c++_ch02_01 (强制类型转换)

    编写一个程序,利用强制类型转换打印元音字母大小写10种形式的ASCII码. 输出的顺序为:大写的字母A,E,I,O,U的ASCII码,小写的字母a,e,i,o,u的ASCII码.所有的ASCII码都用 ...

  7. Caterpillar sis service information training and software

    Cat et sis caterpillar heavy duty truck diagnostics repair. Training demonstration allows.cat electr ...

  8. 远程获得乐趣的 Linux 命令

    今天是我们为期 24 天的 Linux 命令行玩具日历的最后一天.希望你一直有在看,但如果没有,请从头开始,继续努力.你会发现 Linux 终端有很多游戏.消遣和奇怪之处. 虽然你之前可能已经看过我们 ...

  9. 柳暗花明又一村的———for循环

    学习过了do while循环和while循环后,我们终于剩下了循环结构重的最后一个-------for循环 本人认为for循环相比于do while ,while而言.好学一点下面就是我对for循环的 ...

  10. 使用My97DatePicker设置日期的属性示例

    <td>交易日期:</td> <td colspan="3"> <input class="Wdate" id=&qu ...