【ASP.NET】System.Web.Routing - RouteCollection Class
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去解决的。
——————————————————————————————————————————————————————————————————————————————
【ASP.NET】System.Web.Routing - RouteCollection Class的更多相关文章
- 【ASP.NET】System.Web.Routing - HttpMethodConstraint Class
你可以自己定义你的ASP.NET程序接收的get post put 或者delete请求. 使用这个约束的方式为: void Application_Start(object sender, Even ...
- 【ASP.NET】System.Web.Routing - PageRouteHandler Class
用于提供一些属性和方法来定义如何将URL匹配到一个物理文件上面. public PageRouteHandler (string virtualPath, bool checkPhysicalUrlA ...
- 【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 ...
- 【ASP.NET】System.Web.Routing - Route Class
Provides properties and methods for defining a route and for obtaining information about the route. ...
- ASP.net 的URL路由选择(System.Web.Routing.dll)
System.Web.Routing是.net 3.5sp1中新增的一个dll,用它提拱的类可以很方便的实现url的映射,在asp.net WebFrom的编程中可以使客户端请求的URL变得更加的&q ...
- 返璞归真 asp.net mvc (2) - 路由(System.Web.Routing)
原文:返璞归真 asp.net mvc (2) - 路由(System.Web.Routing) [索引页] [源码下载] 返璞归真 asp.net mvc (2) - 路由(System.Web.R ...
- 【ASP.NET】UCenter实现多站点同步登录退出
利用UCenter实现discuz论坛和应用网站同步登录和退出功能 测试环境:Discuz! X3.2.UCenter 1.6..Net Framework 4.0 进入Discuz 后台的UCent ...
- System.Web.Routing入门及进阶 上篇
System.Web.Routing已经作为一个程序集包含在.net3.5sp1中发布了.虽然我们并没有在3.5sp1中发现Asp.net Mvc的踪迹,但是亦以感觉到它离我们不远了. System. ...
- 【ASP.NET】第一个ASP.NET MVC应用程序
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 开发流程 新建Controller 创建Action 根据Action创建View 在Action获取数据并生产ActionResult传递 ...
随机推荐
- css选择问题
<div class="col-lg-4 col-md-6 mb-4"> <div class="card"> <a href=& ...
- tr字符串的梗
工作问题总结 声明:应用程序代码为前人所写,仅仅只是维护代码,暂且不论代码风格瑕疵. 结论: 使用tr“包”起来的字符串,可能会被翻译为不同的语言,此时,应用程序在不同语言环境下可能会表现BUG. 1 ...
- File §2
Previously speaking,File can be seen as one ducument, also can be seen as list of documents like dir ...
- 32个使用python代码片段
1.冒泡排序 lis = [56,12,1,8,354,10,100,34,56,7,23,456,234,-58] def sortport(): for i in range(len(lis ...
- 数据迁移工具Sqoop和DataX功能比较
本文转载自: http://www.cnblogs.com/panfeng412/archive/2013/04/29/data-migration-tool-sqoop-and-datax.html ...
- hive 将一个分区表数据全部插入另外一个分区表
假如现在hive有个分区表A,分区字段为dt 需求是:需要将A表中的数据全部插入到分区表B中 具体步骤如下: 1.create B like A: 2.插入数据 set hive.exec.dynam ...
- [转载]DLL命名规则
程序集是一个部署单元,同时还代表托管代码程序的身份.一般来说一个程序集仅与一个DLL相对应.本节主要讲DLL命名约定,程序集的命名约定与此类似. 要记住,名字空间与DLL和程序集是不同的概念.名字空间 ...
- 跨域的根本原因:JavaScript 的同源策略
摘自:https://blog.csdn.net/liubo2012/article/details/43148705 同源策略限制了一个源(origin)中加载文本或脚本与来自其它源(origin) ...
- 详解BOM头以及去掉BOM头的方法--踩过BOM的大坑
类似WINDOWS自带的记事本等软件,在保存一个以UTF-8编码的文件时,会在文件开始的地方插入三个不可见的字符(0xEF 0xBB 0xBF,即BOM).它是一串隐藏的字符,用于让记事本等编辑器识别 ...
- jboss 报错处理及端口修改
执行文件 ./shutdown.sh -S 后 重启jboss 执行 ./run.sh -Djboss.bind.address=192.168.132.129 & 如果一台机器安装多个jbo ...