Assume an ASP.NET Core Razor Pages site with these pages:
- /admin/index.cshtml
- /admin/users.cshtml
I would like to perform some simple redirections to avoid apparently duplicated content. Below are represented what a request URL would be and what the result redirection should be:
- /admin -> /admin/
- /admin/index -> /admin/
- /admin/users/ -> /admin/users
I would like to perform these redirections from middleware so I don't have to write code for each individual page. How can I perform the above redirections through middleware?
Case 3 seems like the hardest since the middleware will need to detect if "users" is actually just a page and redirect to the page itself instead of allow the URL to be presented as a non-existent directory (/admin/users/). (I'm hoping this won't require me to do checks like System.IO.File.Exists
to see if pages exist. Hopefully the ASP.NET Core framework can do something more elegant.)
Thank you.