I have a problem when I cannot use email addresses as usernames when using microsoft.aspnet.identity (individual user accounts selected when creating a new project - default mvc project template for asp.net 5). I read in many places that this solution:
UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager) { AllowOnlyAlphanumericUserNames = false };
But in the new version of the asp.net ID, the UserManager does not seem to have the UserValidator property. The "UserValidator" is recognized, but I suppose it is added to the UserManager differently. I cannot see any corresponding property in the UserManager.
Edit:
In unit tests in the github registry for "Identity" there is a test for this case. He is currently the last in this file:
https://github.com/aspnet/Identity/blob/dev/test/Microsoft.AspNet.Identity.Test/UserValidatorTest.cs
I suppose this should give a clue to the answer, but I don't see how it will look in my code.
[Theory] [InlineData(" test_email@foo.com ", true)] [InlineData("hao", true)] [InlineData("test123", true)] [InlineData("!noway", true)] [InlineData(" foo@boz #.com", true)] public async Task CanAllowNonAlphaNumericUserName(string userName, bool expectSuccess) { // Setup var manager = MockHelpers.TestUserManager(new NoopUserStore()); manager.Options.User.UserNameValidationRegex = null; var validator = new UserValidator<TestUser>(); var user = new TestUser {UserName = userName}; // Act var result = await validator.ValidateAsync(manager, user); // Assert if (expectSuccess) { IdentityResultAssert.IsSuccess(result); } else { IdentityResultAssert.IsFailure(result); } }
asp.net-core visual-studio-2015 asp.net-core-mvc asp.net-identity-3
rdans
source share