将子文件夹路由到根 URL

时间:2021-05-20 13:23:44

标签: asp.net-core razor-pages asp.net-core-razor-pages

在 Razor 页面项目中,我必须覆盖 ASP.NET Identity 的默认 UI。除了特定的页面要求,我不想要像“/Identity/Account/Whatever”这样的 url - 我的页面将是 /login、/logout 等。

但是,我仍然希望将身份验证页面分组在一个子文件夹中(不要污染顶级文件夹),而是从“根”URL 提供它们。

...
Pages
  /Auth
    Login.cshtml           -> /login
    Logout.cshtml          -> /logout
    ResetPassword.cshtml   -> /resetpassword
    ...
  Index.cshtml
  Privacy.cshtml
...

目前为了实现这一点,我在 Startup.cs 中有以下代码

services.AddRazorPages(options =>
{
  options.Conventions.AddPageRoute("/Auth/Login", "login");
  options.Conventions.AddPageRoute("/Auth/Logout", "logout");
  options.Conventions.AddPageRoute("/Auth/ResetPassword", "resetpassword");
  ...
});

Can this be achieved with folder convention? Also I don't want to have /auth/{page} URLs still working (which is a problem with the current approach).

0 个答案:

没有答案