create user with special characters username using Createasync

harshal bundelkhandi asked on April 13, 2020 15:31

Hi Support,

I want to create user with username having special character like (-,_,@) using the kentico api usermanager.createasync method.i am using email as my username for applicaiton. unable to create & register the user. i am getting below error.

"User name yash-test66@abc.com is invalid, can only contain letters or digits." using below link i am creating the user.

https://docs.kentico.com/k12sp/managing-users/user-registration-and-authentication/enabling-user-registration Thanks, Harshal

Correct Answer

Arjan van Hugten answered on April 14, 2020 08:51

Hi,

I had this problem as well with an MVC site. The cause of my problem was the UserValidator in the usermanager. See this stackoverflow post.

The fix for me was to set the 'AllowOnlyAlphanumericUserNames' to false.

public class AccountController(IOwinContext owinContext)
{
    this.owinContext = owinContext;
    userManager = owinContext.Get<KenticoUserManager<ExtendedUser>>();
    signInManager = owinContext.Get<KenticoSignInManager<ExtendedUser>>();
    userManager.UserValidator = new UserValidator<ExtendedUser, int>(userManager) { AllowOnlyAlphanumericUserNames = false };
}

Note The Owincontext is retrieved with dependency injection. And I have an extended user class with some extra fields so your implementation can differ (With retrieving the user and signin managers and setting the user validator).

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on April 13, 2020 16:54

I suggest checking these web.config settings out and give one or a combination of them a try.

Assuming you're using MVC, in portal engine, it was default to use the email address as the user name. So I'd assume this functionality is not removed in MVC.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.