I'm using ASP.NET Identity, and have extended the IdentityUser class to add my own data.

I'm using data annotations to set the display name, etc. of some fields, but because the UserName field is baked-in, I can't annotate that. Since I'm planning to store an email address in that field, that's one that I really do want to rename!

If data annotations are a non-starter (and I assume they are), is there any other way to achieve the same result?

有帮助吗?

解决方案

Can't you just override the UserName property and add your annotation?

其他提示

The way I'm handling it is by simply not exposing UserName. I have a separate Email property, and I then set UserName to the same thing when saving, behind the scenes.

Also, if you intend on using email addresses as user names, you'll need to have the following:

UserManager.UserValidator = new UserValidator<User>(UserManager) { AllowOnlyAlphanumericUserNames = false };

Otherwise, it won't allow you to set the user name to a valid email address.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top