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

Jalza 781 Reputation points
2021-11-24T14:49:42.423+00:00

I'm developing web application using ASP.NET Core MVC (.NET 5) and Identity for user management. If I navigate to /Identity/Account/Manage page I can see 5 options:

  • Profile
  • Email
  • Password
  • Two-factor authentication
  • Personal data

I added new scaffolded item and check Account/Manage/Layout, and then I remove the
<li>
elements for Two-factor authentication and Personal data but /Identity/Account/Manage/PersonalData and /Identity/Account/Manage/TwoFactorAuthentication links are still accessible.

I would like to remove or disable the access to Two-factor authentication and Personal data options from the site. How can I do it?

Developer technologies | ASP.NET Core | Other

Answer accepted by question author

Jalza 781 Reputation points
2021-11-25T09:00:47.233+00:00

Finally I have managed to disable the pages, following the instructions that appear in the documentation (links in the comments of the first message), but with a little changes.

I added these new scaffolded items:

  • Account/Manage/Layout (previously added)
  • Account/Manage/DeletePersonalData
  • Account/Manage/Disable2fa
  • Account/Manage/DownloadPersonalData
  • Account/Manage/EnableAuthenticator
  • Account/Manage/PersonalData
  • Account/Manage/ResetAuthenticator
  • Account/Manage/TwoFactorAuthentication

For DeletePersonalData, Disable2fa, DownloadPersonalData, EnableAuthenticator, PersonalData, ResetAuthenticator and TwoFactorAuthentication I removed all content from .cshtml and .cshtml.cs files, leaving them empty.

In _ManageNav.cshtml file I removed these list items:

<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>

In ManageNavPages.cs file I removed the following properties and methods:

    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);

As a result I get an 404 HTTP error in the navigator, and this was what I wanted.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.