What's the difference between RouteCollection.Ignore(url, constraints)
and RouteCollection.IgnoreRoute(url, constraints)
?
Background
New MVC projects include this IgnoreRoute
call in Global.asax RegisterRoutes
method to skip routing for requests to .axd locations that are handled elsewhere in the ASP.NET system.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
I wanted to add an additional ignored route to a project and I started to type out the new line. After routes.I
, Intellisense pops up with .Ignore
and .IgnoreRoute
, both sounding about the same.
According to the MSDN docs, you can see that one is an instance method of the System.Web.Routing.RouteCollection
class and the other is an extension method on that class from System.Web.Mvc.RouteCollectionExtensions
.
RouteCollection.Ignore
: "Defines a URL pattern that should not be checked for matches against routes if a request URL meets the specified constraints" (MSDN docs).RouteCollection.IgnoreRoute
: "Ignores the specified URL route for the given list of the available routes and a list of constraints" (MSDN docs).
Both take a route URL pattern and a set of constraints restricting the application of the route on that URL pattern.
Between the source for
System.Web.Mvc.RouteCollectionExtensions
on CodePlex and running a little ILSpy on my local GAC forSystem.Web.Routing.RouteCollection
, it doesn't appear there is a difference, though they seem to have completely independent code to do the same thing.RouteCollection.IgnoreRoute
(via CodePlex source)RouteCollection.Ignore
(via ILSpy decompile)Differences
The only real difference is the obvious difference in location, one being an instance method in the
RouteCollection
class itself and one being an extensions method on that class. After you factor in the code differences that come from instance vs. extension execution (like the vital null check on the extended instance), they appear identical.At their core, they both use the exact same
StopRoutingHandler
class. Both have their own versions of a sealedIgnoreRouteInternal
class, but those versions are identical in code.