admin管理员组文章数量:1125607
I am implementing the routing in 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.
本文标签: NET Core Routing for unwanted folder or extensionStack Overflow
版权声明:本文标题:.NET Core Routing for unwanted folder or extension - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736632790a1945813.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论