I am working on a small ASP.NET MVC project at the moment. The project was released a few months ago. But changes must be implemented for usability and SEO. I decided to use attribute routing to create clean URLs.
Currently the product page is being called:
hostname.tld / controller / GetArticle / 1234
I defined a new route as follows:
[Route("Shop/Article/{id:int}/{title?}", Name = "GetArticle", Order = 0)]
public ActionResult GetArticle(int id, string title = null) {
}
Everything works fine, but due to backward compatibility and SEO reasons, the old route should be accessible. And redirected with HTTP status code 301 to the new URL.
I heard that you can assign multiple routes for a single action, for example:
[Route("Shop/Article/{id:int}/{title?}", Name = "GetArticle", Order = 0)]
[Route("Controller/GetArticle/{id:int}", Name = "GetArticle_Old", Order = 1)]
public ActionResult GetArticle(int id, string title = null) {
}
But I have no idea whether this is a good solution or how to determine which route was invoked?