문제

I see that Webapi uses the RouteCollection from GlobalConfiguration and MVC uses from RouteTable.

I saw an explanation in this link: Difference between RouteTable.Routes and HttpConfiguration.Routes?

Can some one provide some more information or a detailed explanation on these.

Thanks, Sam

도움이 되었습니까?

해결책

Sam,

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top