Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How do I set AllowOnlyAlphanumericUserNames to false in ASP.Net Identity Core?

$
0
0

I see the examples all over in previous versions of Identity.
But these properties do not seem to exist in Core:
1) AllowOnlyAlphanumericUserNames
2) UserValidator - off of UserManager

I am trying to set ASP.Net Identity Core in my project. The thing is we will be using Windows Authentication rather then forms authentication. I am able to get the Authorize tag to work on the home controller by setting these properties in the launch.settings for iisSettings:

"windowsAuthentication": true,"anonymousAuthentication": false,

So now in my header I see my username through my layout file using this:

@User.Identity.Name

So my username in the upperright of my header looks like this:

[domain\username\]

So now the Authorize tag works. If I turn off windows auth and go back to anonymous auth I will get the unauthorized status for the page. And if go back to Windows auth I can see the home/index page again. Not really much to do with Identity yet.

Now I try to make a Create User Page which will eventually really be a "Add User" from Active Directory page. So I am trying to store the UserName in this format:

domain\username

Here is my create code:

[HttpPost]
public async Task<IActionResult> CreateUser(CreateUserViewModel createUserModel)
    {
        if (ModelState.IsValid)
        {
            AppUser user = new AppUser
            {
                UserName = createUserModel.Name,
                Email = createUserModel.Email
            };
            IdentityResult result
                = await _userManager.CreateAsync(user, createUserModel.Password);

            if (result.Succeeded)
            {
                return RedirectToAction("Index");
            }
            else
            {
                foreach (IdentityError error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
        }
        return View(createUserModel);
    }

But I get back this message:

User name 'domain\username' is invalid, can only contain letters or digits.

So through reading I keep seeing that you can use these properties off of the UserManager to take care of this:

AllowOnlyAlphanumericUserNames
UserValidator

But these properties don't seem to exist in Identity Core. Is this true? How can I fix this problem in Core? Very stuck. Can't find the property from default implementations or if I try to create Custom User Validators.

<div class="post-taglist"></div>
<div class="post-menu">share|edit|delete|flag</div>

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>