Search code examples
asp.net-coreasp.net-identity

Identity 3.1 - when changing email the user name gets changed, can this be avoided?


A default ASP .NET Core 3.1 Identity mixes the email and user name pretty much together. I separated them in the Login and Registration pages by spawning them into my project and modifying them manually. But Change email sets the user name to the new email. Can I use some global flag to fix that strange behaviour? If not, which pages do I need to spawn and modify manually to get it right?


Solution

  • The behavior you are describing is not built into ASP.NET Core Identity but instead it is built into the default Identity UI that is the set of pages that provide the default pages for managing identities. The Identity system itself is completely transparent here and always handles both the user name and the email address separately.

    This however also means that you cannot magically change some Identity setting to split this up properly. Instead, you will have to edit the UI for this. Unless I am missing something, the following pages of the default Identity UI set both the user name and the email address:

    • Register.cshtml: When a user registers.
    • ExternalLogin.cshtml: When a user registers through an external provider.
    • ConfirmEmailChange.cshtml: When the user confirms an email change by passing the change token.