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

Jalza 736 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?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,164 questions
{count} vote

Accepted answer
  1. Jalza 736 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.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful