To perform a "courtesy redirect" in an MVC application, open your main controller and update the Index action. In my case the app is a Durandal SPA app, so the main Index method looks like this:
public class DurandalController : Controller
{
public ActionResult Index()
{
return View();
}
}
We need to check the request and if necessary redirect. It ends up looking like this:
public class DurandalController : Controller
{
public ActionResult Index()
{
var root = VirtualPathUtility.ToAbsolute("~/");
if ((root != Request.ApplicationPath) && (Request.ApplicationPath == Request.Path))
return Redirect(root + "#");
else
return View();
}
}
Redirection only comes into play once in the session lifecycle of a SPA app because it is loaded from the server only once per session. Implemented like this it has no consequences for other controllers and the URLs that they handle.