Near the bottom of my routing registration, if a URL has a .js
extension, I'd like to handle it with a particular controller (most .js content is served statically, but some is special and needs to be served via a controller). However, the following route is being skipped, and the catch-all route is handling the request.
routes.MapRoute("ContentScript", "{script}.js",
new { controller = "Content", action = "Script" },
new[] { "NameSpace.Controllers" }
);
What is the right way to do this?
In the route directly after that one every remaining request is routed like so (and this works and catches the .js files), so the issue is not in any part but the url
parameter):
routes.MapRoute("ContentScript", "{*path}",
new { controller = "Content", action = "Index" },
new[] { "NameSpace.Controllers" }
);
I also tried the following, without success:
routes.MapRoute("ContentScript", "{*script}",
new { controller = "Content", action = "Script" },
new { script = new RegexConstraint("\\.js$") },
new[] { "NameSpace.Controllers" }
);