Reputation: 13175
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:
What I don't like about it:
Controller Actions - use the routes & controllers to do the redirect
What I like about it:
What I don't like about it:
Any suggestions would be great, thanks.
Upvotes: 4
Views: 990
Reputation: 26116
Among those two choices, I would go with Controller actions. Controllers aren't required to return a view--I believe you can even make a controller method return void
with ASP.NET MVC. The reason I like this option is because of the database interaction--I think spinning up a database in the BeginRequest is going to affect overall performance.
If that's not a concern, I think putting it with the rest of the routing information makes the most sense (i.e. with BeginRequest).
Upvotes: 3