问题
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/*")
回答1:
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
来源:https://stackoverflow.com/questions/9918066/mvc3-map-routes-to-static-file-structure