Reputation: 71
I am implementing the routing in .net Core 8.0 project. First goal is to redirect any .aspx page request to the latest common page. I have placed these combinations to address all possibilities. it is working fine.
[HttpGet("/{filename}.aspx")]
[HttpGet("/{folder1?}/{filename}.aspx")]
[HttpGet("/{folder1?}/{folder2?}/{filename}.aspx")]
[HttpGet("/{folder1?}/{folder2}/{folder3}/{filename}.aspx")]
[HttpGet("/{folder1?}/{folder2}/{folder3}/{folder4}/{filename}.aspx")]
[HttpGet("/{folder1?}/{folder2}/{folder3}/{folder4}/{folder5}/{filename}.aspx")]
[HttpGet("/{folder1?}/{folder2}/{folder3}/{folder4}/{folder5}/{folder6}/{filename}.aspx")]
[HttpGet("/{folder1?}/{folder2?}/{folder3?}/{folder4?}/{folder5?}/{folder6?}/{folder7?}/{filename}.aspx")]
But now the challenge is, I want it to be extended for various folders too, as they are no more available. So if a url is starting from certain folder, I need to redirect them.
One option is to repeat the above code for each folder, but it will be too much to manage... So I thougt of experiementing with RegEx as shown below, but they are not working in all scenarios.
For example, I want any url starting with portal, should get redirect to the page.
[HttpGet("{url:regex(.*)}.aspx")]
[HttpGet("/Site/{url:regex(.*)}")]
[HttpGet("/portal/{url:regex(.*)}")]
[HttpGet("/goBig/{url:regex(*)}")]
[HttpGet("/Go-Big/{url:regex(.*)}")]
I have placed these code in a method under controller. I am decorating HttpGet for this method.
public IActionResult NotReadyPages()
{
return RedirectToAction("CatamaransForSale", "Boat");
}
Please advise, if this is the correct route, or would you recommend better way to maintain these, I could have many unwanted folders to be redicted because of old reference in the Google Console.
Upvotes: 0
Views: 41