Reputation: 13887
I have two routes mapped in my RouteConfig:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Content",
url: "Content/{item}.css",
defaults: new
{
controller = "Content",
action = "GetContent"
}
);
routes.MapRoute(
name: "Reports",
url: "SubFolder/App/Views/OtherFolder/Reports/{report}.html",
defaults: new
{
controller = "Reports",
action = "GetReport"
}
);
}
For a URL like
http://example.com/SubFolder/App/Views/OtherFolder/Reports/someReport.html
The 2nd Route correctly fires off the GetReport
method in ReportsController
:
public ActionResult GetReport(string report) { .... }
But for a URL like
I would expect the 1st Route to fire off the GetContent
method in ContentController
:
public ActionResult GetContent(string item) { ... }
but it does not. Any ideas how I can get this routed properly? Ideally I'd like any GET request for anything under the Content
folder to be routed to ContentController
, but I'm just starting with css files directly in that folder.
I'm on IIS 8.0, MVC 4.0, and using VS2012 if that makes a difference.
Upvotes: 1
Views: 761
Reputation: 483
By default, MVC does not route static files and just tries to serve a static .css file under the requested path. Just remove the .css ending and the route will be used.
Edit: To be clearer the IIS tries to serve these static files before the MVC routehandling even comes into play.
Upvotes: 2