Difference between RouteTable.Routes and HttpConfiguration.Routes?
The HttpConfiguration
class is specific to WebApi making it reusable outside of IIS (e.g. For self hosting). The RouteTable
version is for IIS only.
https://stackoverflow.com/questions/23381962/routetable-routes-vs-httpconfiguration-routes
RouteTable is the underlying structure for routing used by asp.net/System.Web.
When you run on IIS using ASP.NET (which is the default template in Visual Studio) the routes are written to the routetable, and WebHost is used to shim between ASP.Net/System.Web and Web API. In that case the routes are written to the RouteTable.
But Web API can run in WCF self host or Owin self host as well (in a console app, a service or hosted in your application code). In these cases ASP.NET (or more accurately) system.web is not being used as the hosting layer. These two hosts do not provide an abstraction for Routing and Web API implements its own routing.
To keep the user code portable between different hosts, the routes are written to a separate collection, and then each host makes a different use of it.
As a side note, this is also the reason using HttpContext.Current is not recommended in Web API if you ever plan to run Web API in a none IIS host.
I am wondering why routes seem to be configurable from both the HttpConfiguration object and the RouteTable class? Clearly the two .Routes properties are not of the same type, but they seem to stay in-sync. Is there a chance they could get out-of-sync? I'm wondering though, from a Web API perspective, should RouteTable.Routes ever be used?
WebAPI can be hosted outside of IIS so they needed an abstraction on the RouteTable.Routes.
That makes sense. After I did some more digging, I see that the HttpConfiguration.Routes collection really just wraps the RouteTable.Routes collection (when hosted on ASP.NET) so I suppose there's really no big difference between the two.
2个属性的类型是不同的:
RouteTable.Routes 的类型是System.Web.Routing.RouteCollection Assemblies:System.Web.dll, System.Web.Routing.dll
HttpConfiguration.Routes 的类型是 System.Web.Http.HttpRouteCollection Assembly: System.Web.Http (in System.Web.Http.dll)
下面的扩展方法,只对RouteTable.Routes做了
https://docs.microsoft.com/en-us/previous-versions/aspnet/dn253837(v%3Dvs.113)
#region Assembly Microsoft.Owin.Host.SystemWeb, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// packages\Microsoft.Owin.Host.SystemWeb.4.0.0\lib\net451\Microsoft.Owin.Host.SystemWeb.dll
#endregion
using Owin;
namespace System.Web.Routing
{
//
// Summary:
// Provides extension methods for registering OWIN applications as System.Web routes.
public static class RouteCollectionExtensions
Difference between RouteTable.Routes and HttpConfiguration.Routes?的更多相关文章
- Sails 关闭自动路由 Automatic Routes 功能。
Sails 关闭自动路由 Automatic Routes 功能. Sails 中的路由两种:Custom Routes 和 Automatic Routes,自定义路由和自动路由.详见文档: Sai ...
- Angular2 - Starter - Routes, Route Resolver
在基于Angualr的SPA中,路由是一个很重要的部分,它帮助我们更方便的实现页面上区域的内容的动态加载,不同tab的切换,同时及时更新浏览器地址栏的URN,使浏览器回退和前进能导航到历史访问的页面. ...
- Laravel中如何将单个routes.php分割成多个子文件
随着业务逻辑越来越复杂,routes.php文件也会变得越来越庞大,为了便于管理,我们可以像管理配置文件那样将其分割成多个子文件,这实现起来很简单: // app/routes.php ... // ...
- Openstack Restful API 开发框架 Paste + PasteDeploy + Routes + WebOb
目录 目录 Paste PasteDeploy Routes WebOb 简介 WSGI入口 Paste和PasteDeploy 配置文件 pasteini 中间件的实现 Routes WebOb 参 ...
- PLAY2.6-SCALA(二) Actions, Controllers ,Results,routes
一.Action(play.api.mvc.Action) 大多数的应用的请求都是由action进行处理,并生成一个结果给客户端,Action有多种创建方式: 1. Action {Ok(" ...
- MVC涉及RouteTable自定义路径
Routing 到目前为止,我们已经解决了MVC的很多问题,但忽略了最基本的最重要的一个问题:当用户发送请求时,会发生什么? 最好的答案是“执行Action 方法”,但仍存在疑问:对于一个特定的URL ...
- ASP.NET Web API 控制器创建过程(一)
ASP.NET Web API 控制器创建过程(一) 前言 在前面对管道.路由有了基础的了解过后,本篇将带大家一起学习一下在ASP.NET Web API中控制器的创建过程,这过程分为几个部分下面的内 ...
- ASP.NET Web API路由系统:Web Host下的URL路由
ASP.NET Web API提供了一个独立于执行环境的抽象化的HTTP请求处理管道,而ASP.NET Web API自身的路由系统也不依赖于ASP.NET路由系统,所以它可以采用不同的寄宿方式运行于 ...
- WebApi学习总结系列第四篇(路由系统)
由于工作的原因,断断续续终于看完了<ASP.NET Web API 2 框架揭秘>第二章关于WebApi的路由系统的知识. 路由系统是请求消息进入Asp.net WebApi的第一道屏障, ...
随机推荐
- 再论IBatisNet + Castle进行项目的开发
随着项目的进展,Castle和IBatisNet给我的惊喜更多.Com+很重,不需要分布式的中小项目慎用,NHibernate虽好,NHibernate的2005-9-20发布了最新版本1.0-rc1 ...
- [MySQL] 变量(参数)的查看和设置 [转]
[MySQL] 变量(参数)的查看和设置 类似于Oracle的参数文件,MySQL的选项文件(如my.cnf)用于配置MySQL服务器,但和Oracle叫法不一样,在MySQL里, 官方叫变量(Var ...
- CentOS7防火墙设置--iptables
CentOS7默认使用的是firewalld而不是之前的iptables.需要先停用firewalld. systemctl stop firewalld 安装 iptables 服务 yum -y ...
- 火狐 a 标签 download 属性,要在 a 标签添加到页面中才生效;
在 chrome 中,如果需要设置点击下载文件,需要创建一个 a 标签,指定 download 属性和 href 属性即可, var aLink = document.createElement('a ...
- 【IE兼容性】代码中多语言样式+IE不兼容解决
一.代码中样式根据不同语言对IE做不兼容解决 二.代码逻辑: 1. 后台返回语言信息: result.addObject("language",getLocaleStr()); ...
- ORA-08002: sequence TESTTABLE1_ID_SEQ.CURRVAL is not yet defined in this session (未完全解决)
说明: 断开连接后 重新连接执行序列号当前值查找 会报错. 解决方法一:先查询序列号下一个值 SELECT testTable1_ID_SEQ.nextval from dual;
- 打印出所有的"水仙花数"
题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身.例如:153是一个"水仙花数",因为153=1 ...
- Django框架错误处理
错误处理 在一些网站开发中.经常会需要捕获一些错误,然后将这些错误返回比较优美的界面,或者是将这个错误的请求做一些日志保存.那么我们本节就来讲讲如何实现. 常用的错误码: 404:服务器没有指定的ur ...
- IntelliJ创建main函数、for循环,System.out.println()等快捷建(转载)
在编写代码的时候直接输入psv就会看到一个psvm的提示,此时点击tab键一个main方法就写好了. psvm 也就是public static void main的首字母. 依次还有在方法体内键入f ...
- [Spring ] RequestParam VS PathVariable
仔细一想,感觉没啥需要区分的呢.就是简单明确了两种url定义的背景. PathVariable这种,主要是针对restful类型的url.这种path的定义就要根据restful的规范了. 根据昨天开 ...