Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 272
fractor Avatar asked Dec 05 '25 09:12

fractor


1 Answers

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

like image 169
fractor Avatar answered Dec 09 '25 15:12

fractor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!