문제

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