I have an existing web site that has a folder structure to documents to be downloaded.
I am replacing this site with a new MVC site.
Custom routing seems to be the way to go to support legacy URLs and re-route to the new URL.
For example, there are a lot of hyperlinks in the wild that have been bookmarked by users, and sent out in emails. I would like them to continue to work.
My old URL would look like this:
mywebsite.com/Documents/2014/February/nameofthefile.pdf
I want to write a custom route that would ignore the /2014/February part, then grab just the file name.
Would this work?
routes.MapRoute( "Documents", // Route name "Documents/{Year}/{Month}/{FileName}", // URL with parameters new { controller = "Reports", action = "GetReportByFileName" }
Hi agent,
Thanks for your post.
agent_smith
I want to write a custom route that would ignore the /2014/February part, then grab just the file name.
If you want to ignore the the /2014/February part,you can add
Year=UrlParameter.Optional,Month=UrlParameter.Optional
More information:
Pease check these:
http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC
http://www.dotnetcurry.com/showarticle.aspx?ID=970
Hope this can be helpful.
Best Regards,
Eileen