From this answer on another thread, I've created a redirect controller to route my old aspx files to my new MVC pages.
RouteConfig.cs:
routes.MapRoute(
name: "About",
url: "aboutus.aspx",
defaults: new { controller = "Redirect", action = "About" }
);
RedirectController.cs:
public ActionResult About()
{
return RedirectPermanent("/Home/About");
}
This works perfectly, as I have a view in /Views/Home/About.cshtml
. However, if I try to redirect, say a .PDF file, it doesn't work...
RouteConfig.cs:
routes.MapRoute(
name: "MyPDF",
url: "somefile.pdf",
defaults: new { controller = "Redirect", action = "MyPDF" }
);
RedirectController.cs:
public ActionResult MyPDF()
{
return RedirectPermanent("/Documents/somefile.pdf");
}
This goes to a standard 404 not found page. I've also tried an absolute path with no luck:
RedirectController.cs:
public ActionResult MyPDF()
{
return RedirectPermanent("http://mydomain.com/Documents/somefile.pdf");
}
But still no luck. Any ideas?
edit: the reason for the redirect is because 3rd party sites are linking to old PDF files (they used to exist on the website root, now they're in /Documents/
. I'd like to 301 redirect to the correct file.