McGarnagle
McGarnagle

Reputation: 102743

MVC3 map routes to static file structure

Let's say I have an MVC application that routes requests according to the standard /{controller}/{action} pattern. I also want to be able return static files from a nested directory structure. For example, I want the root URL:

/MyApplication/Static/folder/subfolder/somefile.xml

to return the file at the physical location ~/Static/folder/subfolder/somefile.xml, and so on.

Is this what the "MapPageRoute" method is for? If so, is it possible to do something like this?

routes.MapPageRoute("static_file_router", "Static/*", "~/Static/*")

Upvotes: 1

Views: 1816

Answers (1)

lahsrah
lahsrah

Reputation: 9173

I think you should use IIS to map this instead. Static files don't need to go through the ASP.NET pipeline and slow down the requests unnecessarily.

MapPageRoute is for legacy WebForms pages.

e.g.

routes.MapPageRoute("", 
                    "SalesReport/{locale}/{year}/{*queryvalues}", 
                    "~/sales.aspx");

See http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.mappageroute.aspx

Upvotes: 1

Related Questions