【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传递 ...
随机推荐
- 正确把mysql数据库从windows迁移到linux系统上的方法
(一)用mysqldump命令导出数据库文件: 在windows下cd到Mysql的bin目录: c:/data.txt这个目录和导出的文本名可以自己随便取,-B 后面的是表名,我要导出的表明叫use ...
- Qt5 信号重载
下面以最常用的QComboBox为例说明. [1]Qt4风格的connect 示例代码: connect(ui->comboBox, SIGNAL(activated(int index)), ...
- xshell中出现的绿色背景的文件夹
这种文件夹表示权限为777的文件夹 可以使用chmod 777 fileName进行权限修改 如果需要将文件夹以及其子文件夹的权限全部置为777 chmod 777 -R directoryName/ ...
- 转:【专题五】TCP编程
前言 前面专题的例子都是基于应用层上的HTTP协议的介绍, 现在本专题来介绍下传输层协议——TCP协议,主要介绍下TCP协议的工作过程和基于TCP协议的一个简单的通信程序,下面就开始本专题的正文了. ...
- 产品经理-需求分析-用户故事-敏捷开发 详解 一张图帮你了解Scrum敏捷流程
产品经理-需求分析-用户故事-敏捷开发 详解 用户故事是从用户的角度来描述用户渴望得到的功能.一个好的用户故事包括三个要素:1. 角色:谁要使用这个功能.2. 活动:需要完成什么样的功能.3. 商业价 ...
- linux下mysql 8.0忘记密码后重置密码
1://免密码登陆 找到mysql配置文件:my.cnf, 在[mysqld]模块添加:skip-grant-tables 保存退出: 2://使配置生效 重启mysql服务: service ...
- Poj3253 Fence Repair (优先队列)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 67319 Accepted: 22142 De ...
- Django框架----Form组件
Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...
- nginx的gzip压缩功能
我们在开发网站的时候,应该要考虑到pv,因为pv比较大可能会造成服务器带宽不够用,进而导致用户体验变差. 这个时候我们就可以考虑用nginx的gzip功能. 在nginx中开启gzip压缩功能很简单, ...
- 初识 GitHub
初识 GitHub 一.注册账号 GitHub 官网:https://github.com/ 点击右上角sign up,进行注册,注册界面如下: 填写用户名,邮箱地址,密码,下滑点击绿色按钮:Crea ...