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. Abandoned country(最小生成树+树形DP)

    #include<bits/stdc++.h> using namespace std; struct node{ int u, v, w, nex; bool gone; node(){ ...

  2. 20155228 2017-5-31 课堂测试:编写MyOD.java

    20155228 2017-5-31 课堂测试:编写MyOD.java 题目和要求 编写MyOD.java:用java MyOD XXX实现Linux下od -tx -tc XXX的功能 提交测试代码 ...

  3. mysql 创建用户,删除用户,增加权限

    1,查询mysql 数据库已经存在的用户: SELECT USER,HOST FROM MYSQL.USER; 2,创建mysql 用户: '; USERNAME:用户名 HOST:主机,PASSWO ...

  4. python os.path.dirname()

    ----返回文件所在的路径 ----如果path变量直接是文件名则返回空

  5. mybatis源码解析9---执行器Executor解析

    从前面分析我们知道了sql的具体执行是通过调用SqlSession接口的对应的方法去执行的,而SqlSession最终都是通过调用了自己的Executor对象的query和update去执行的.本文就 ...

  6. 移植并修改成功的模拟iic读写EEPROM at24c02

    2010-04-24 12:58:00 注:如果要读24c128或264,地址位为16位的.现在的地址位为8位. protues仿真图 源程序如下: #include <iom16v.h> ...

  7. HDU 1527 取石子游戏 (威佐夫博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是 ...

  8. Redhat 简单本地yum 配置

    Redhat 简单本地yum 配置 一.将redhat 系统的镜像挂载到系统上 Vmware Workstion 环境下: [虚拟机设置]--[硬件]--[CD/DVD]--[使用ISO映像文件]-- ...

  9. IPERF 网络性能测试

    Iperf 是一个网络性能测试工具.Iperf可以测试最大TCP和UDP带宽性能.Iperf具有多种参数和UDP特性,可以根据需要调整.Iperf可以报告带宽,延迟抖动和数据包丢失. Iperf 参数 ...

  10. python 网页cookie的使用

    网页cookie的使用 Cookie,指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密) # opener的概念当你获取一个URL你使用一个opener(一 ...