Remove/Disable "Two-factor authentication" 和 "Personal Data" 来自 /Identity/Account/Manage 页

Remove/Disable "Two-factor authentication" and "Personal Data" from /Identity/Account/Manage page

我正在使用 ASP.NET Core MVC (.NET 5) 和用户管理身份开发 Web 应用程序。如果我导航到 /Identity/Account/Manage 页面,我可以看到 5 个选项:

我想从页面中删除双因素身份验证个人数据 选项。并且还删除或禁用对这些功能的访问。我该怎么做?

编辑:

我添加了新的脚手架项并检查了 Account/Manage/Layout,然后删除了 双因素身份验证 <li> 元素个人数据,但 /Identity/Account/Manage/PersonalData 和 /Identity/Account/Manage/TwoFactorAuthentication 链接仍可访问。

最后,我按照文档中显示的说明 (Disable a page) 设法禁用了这些页面,但稍作更改。

我添加了这些新的脚手架项目:

  • Account/Manage/Layout(之前添加)
  • Account/Manage/DeletePersonalData
  • Account/Manage/Disable2fa
  • Account/Manage/DownloadPersonalData
  • Account/Manage/EnableAuthenticator
  • Account/Manage/PersonalData
  • Account/Manage/ResetAuthenticator
  • Account/Manage/TwoFactorAuthentication

对于 DeletePersonalData、Disable2fa、DownloadPersonalData、EnableAuthenticator、PersonalData、ResetAuthenticator 和 TwoFactorAuthentication,我删除了 .cshtml.cshtml.cs[= 中的所有内容48=] 文件,让它们 .

_ManageNav.cshtml 文件中,我删除了这些列表项:

<li class="nav-item"><a class="nav-link @ManageNavPages.TwoFactorAuthenticationNavClass(ViewContext)" id="two-factor" asp-page="./TwoFactorAuthentication">Two-factor authentication</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.PersonalDataNavClass(ViewContext)" id="personal-data" asp-page="./PersonalData">Personal data</a></li>

ManageNavPages.cs 文件中,我删除了以下属性和方法:

    public static string DownloadPersonalData => "DownloadPersonalData";
    public static string DeletePersonalData => "DeletePersonalData";
    public static string PersonalData => "PersonalData";
    public static string TwoFactorAuthentication => "TwoFactorAuthentication";
    public static string DownloadPersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DownloadPersonalData);
    public static string DeletePersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, DeletePersonalData);
    public static string PersonalDataNavClass(ViewContext viewContext) => PageNavClass(viewContext, PersonalData);
    public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) => PageNavClass(viewContext, TwoFactorAuthentication);

结果我在导航器中收到 404 HTTP 错误,这正是我想要的。