fractor
fractor

Reputation: 1650

How to allow a null username in ASP.NET Core Identity

The registration workflow for my application allows a username to be set only after the email address has been confirmed. Using the defaults in Microsoft.AspNetCore.Identity 1.1.1.0, with Entity Framework generates an AspNetUsers table in the database, with a nullable UserName column. However, if I try to supply an instance of IdentityUser with a null UserName to UserManager.CreateAsync() I get the error: "User name '' is invalid, can only contain letters or digits.".

I would like to avoid setting a temporary non-null value, as the username should be unique but not an email address. Other workarounds (e.g. guid) just seem like a hack.

What's the best way to allow null for a null UserName?

Upvotes: 5

Views: 3214

Answers (1)

fractor
fractor

Reputation: 1650

It looks like usernames are not intended to be null. A separate DisplayName property or similar is probably the way to go. https://github.com/aspnet/Identity/issues/1186

Upvotes: 1

Related Questions