问题
We're developing a new system to replace an existing system.
The new system is ASP.NET MVC so we're defining routes to our controllers and actions as normal.
The old system as traditional ASP.NET so the URLs consist of lots of .aspx pages.
We want to set up redirects so that when a user tries to access /Homepage.aspx
(lots of users would have that bookmarked), they'll get redirected to the new system's default route, which is just /
What is the best way for me to do this?
edit: @Chance suggested below that I specify the route:
routes.MapRoute("Homepage", "Homepage.aspx", new { controller = "controller", action = "homepage" });
This works, but I'd like to do a redirect because I don't want Homepage.aspx
in the address bar. Is there anything else I can do?
回答1:
You may take a look at the following blog post which illustrates how you could implement a legacy route handler which will perform 301 permanent redirects.
回答2:
Put this code in your global.asax file:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Url.ToString().ToLower().Contains("homepage.aspx"))
{
// use RedirectPermanent for 301, or Redirect for 302
Context.Response.RedirectPermanent("/");
}
}
You could modify this code to apply to other old ".aspx" pages as well.
回答3:
you can just give your default controller/action an additional route that is hardcoded. Ie
routes.MapRoute("Homepage", "Homepage.aspx", new { controller = "controller", action = "homepage" });
回答4:
Another option would be to simply create a static page to replace HomePage.aspx with a meta redirect. This would allow you to present the user with a message informing them that the site has changed, and urge them to update their bookmarks.
You can extend this to the entire site by creating a custom error handler for 404 that points to either a static page, or a specific URL.
来源:https://stackoverflow.com/questions/4626166/how-to-redirect-homepage-aspx-to-an-mvc-default-route