I\'m working on migrating an existing ASP.NET web site into an MVC project. There are several (60+) pages that I don\'t want to rewrite just yet, and so I\'m wondering if th
I solved this using a controller which returns the contents of the file. It is not a perfect and fast solution but it works.
routes.MapRoute(
"legacyroutes",
"{filename}.aspx",
new { controller = "Home", action = "RedirectFile"}
);
And the controller:
public class HomeController : Controller
{
public ActionResult RedirectFile(string filename)
{
string url = Url.Content("~/Legacy/"+filename+".aspx");
Redirect(url); // or other code to process the file
}
}
Details and other examples here: http://maxivak.com/dynamic-url-rewriting-on-asp-net-mvc/
Not sure if you still need this, but you could solve this with a dirty solution:
Use HttpContext.Current.Request.MapPath("")
to get the physical location of the route, and then loop over all aspx files (and anything else you want to map) using the DirectoryInfo/FileInfo
classes. You can then dynamically register alternative paths for your files.
I've done a prototype and it appears to be working, although of course, the devil is always in the details.
Cheers,