MVC3 map routes to static file structure

醉酒当歌 提交于 2019-12-24 18:05:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!