Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net MVC Routing not matching some file extensions

I am having trouble with routes not matching when the contain certain file extensions in them. I suspect it might be an IIS problem but I can't seem to track it down.

First off, I have RouteExistingFiles turned off:

routes.RouteExistingFiles = false;

And then I have the following route:

routes.MapRoute("", "category/{category}.aspx", new { controller = "Category", action = "View" });

and the following url does not match this route:

http://mysite/category/test.aspx

But, if I remove the file extension and cange the route to:

routes.MapRoute("", "category/{category}", new { controller = "Category", action = "View" });

Then the above url matches with {category} being set to "test.aspx"

I also have the same problem with this route:

routes.MapRoute("sitemap", "sitemap.xml", new { controller = "Resource", action = "Sitemap" });

The strange thing is that I am not having this problem with all routes with file extensions. The following routes seem to be working just fine for me:

routes.MapRoute("", "favicon.ico", new { controller = "Resource", action = "Favicon" });
routes.MapRoute("", "min.css", new { controller = "Resource", action = "Css" });
routes.MapRoute("", "min.js", new { controller = "Resource", action = "JavaScript" });
routes.MapRoute("", "rsd.xml", new { controller = "MetaWeblog", action = "Rsd" });

Is there something I should be aware of with the .aspx and .xml extensions? Could this be an IIS Problem? Is there a better way to debug this than just using RouteDebugger?

like image 677
Luke Foust Avatar asked May 30 '12 15:05

Luke Foust


1 Answers

Is your problem is the request is not being directed to those actions if the url contains .xml or .aspx?

then I guess this should be true,

routes.RouteExistingFiles = true;

UPDATE:

I tested in two scenarios with the following route for a site running in IIS 7.

routes.MapRoute("sitemap", "{sitemap}.xml", 
                   new { controller = "Resource", action = "Sitemap" });

With RouteExistingFiles is false,

In this case when the sitemap.xml file is there then the request is directed to that file else the request is directed to the action.

With RouteExistingFiles is true,

When the sitemap.xml file exists or not all the time the request is being directed to the action.

like image 93
VJAI Avatar answered Oct 20 '22 15:10

VJAI