Yes, routes.IgnoreRoute("{x}.axd/{*y}")
will still work.
Placeholder - {placeholderName}
The values within curly brackets are known as placeholders
. These are simply variables and can be named whatever you want. When evaluating incoming URLs, the names don't matter at all. But when generating URLs or working out action method parameters or model property values, those names must match.
In the case of IgnoreRoute
, there are no URLs generated, so those names are basically syntactic surgar.
Catch-All Placeholder - {*placeholderName}
The asterisk *
indicates a catch-all placeholder. It is basically saying "match the URL, even if the rest of the segments from here to the end of the URL doesn't match the incoming URL".
Forward Slash - /
When using a catch-all placeholder as in this example, it indicates 1 or more optional segments. Since these segments are optional, so too is the right-most /
. This is the same behavior when using the Default
route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
When the right-most segment is optional and it is not supplied in the URL (Home/About
), this makes the right-most slash /
optional as well. If the next right-most segment is also optional and omitted, the next right-most /
is also optional. This explains why the default route matches the home page /
instead of requiring //
in order to match.
This behavior is special and only applicable to /
. If you have placeholders with a different delimiter, such as {foo}-{bar}
and bar
is marked UrlParameter.Optional
, -
is still required (in fact, {bar}
is required as well). /1-2
matches, /1-
and /1
do not match.
Query String - ?key=value&key2=value2
Query string parameters are ignored completely when matching incoming routes. The reason why query string values are provided to MVC's ModelBinder
and as action method parameters are because they are processed by value providers later on in the request.
On the other hand, when generating URLs (such as for ActionLink
), any left over non-matching route values that are supplied (either in the request or directly) are added to the end of the generated URL as query string parameters.
@Html.ActionLink("Link", "Home", "About", new { key = "value", key2 = "value2" }, null)
Assuming the Default
route, this ActionLink
will generate the URL
/Home/About?key=value&key2=value2