I have a legacy asp.net website I am migrating to asp.net mvc.
I would like to permanently redirect existing urls to the asp.net mvc controllers. I have controllers with views for the new location for these links, and I would like to do a 301 redirect on the existing pages to the new views.
I have two different types of urls:
Type 2 urls are the result of an existing url rewriter module from before asp.net mvc route handling.
I have existing redirect code:
Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", url);
Response.End();
Where should I do the redirect?
I see two options:
Application_BeginRequest - use regex to parse the url
What I like about it:
- I already check for uppercase urls to redirect to lowercase urls here
- I have the chance to work directly with the response without having to return an ActionResult
What I don't like about it:
- Url type #2 from the top has to be mapped into the new controllers/views, meaning I need to do some database work to get the path for the url
Controller Actions - use the routes & controllers to do the redirect
What I like about it:
- I can cleanly do the database work I need
What I don't like about it:
- The controller needs to return a view, and I am directly manipulating the Response stream to create the 301.
Any suggestions would be great, thanks.