There is no such thing as a técnico
problem in using accents, or even spaces. Even though what is compared is not Name
but NormalizedName
, this by definition should allow comparison with special characters: Unicode® Standard Annex #15
Let's take a look at the source code Identity
:
RoleStore.cs
/// <summary>
/// Finds the role who has the specified normalized name as an asynchronous operation.
/// </summary>
/// <param name="normalizedName">The normalized role name to look for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
/// <returns>A <see cref="Task{TResult}"/> that result of the look up.</returns>
public virtual Task<TRole> FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
return Roles.FirstOrDefaultAsync(r => r.NormalizedName == normalizedName, cancellationToken);
}
Note that the property that is used to find a Role is NormalizedName
Now let's look at the method you should be using to create a Role
:
RoleManager.cs
/// <summary>
/// Creates the specified <paramref name="role"/> in the persistence store.
/// </summary>
/// <param name="role">The role to create.</param>
/// <returns>
/// The <see cref="Task"/> that represents the asynchronous operation.
/// </returns>
public virtual async Task<IdentityResult> CreateAsync(TRole role)
{
ThrowIfDisposed();
if (role == null)
{
throw new ArgumentNullException(nameof(role));
}
var result = await ValidateRoleAsync(role);
if (!result.Succeeded)
{
return result;
}
await UpdateNormalizedRoleNameAsync(role);
result = await Store.CreateAsync(role, CancellationToken);
return result;
}
/// <summary>
/// Updates the normalized name for the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The role whose normalized name needs to be updated.</param>
/// <returns>
/// The <see cref="Task"/> that represents the asynchronous operation.
/// </returns>
public virtual async Task UpdateNormalizedRoleNameAsync(TRole role)
{
var name = await GetRoleNameAsync(role);
await Store.SetNormalizedRoleNameAsync(role, NormalizeKey(name), CancellationToken);
}
/// <summary>
/// Gets a normalized representation of the specified <paramref name="key"/>.
/// </summary>
/// <param name="key">The value to normalize.</param>
/// <returns>A normalized representation of the specified <paramref name="key"/>.</returns>
public virtual string NormalizeKey(string key)
{
return (KeyNormalizer == null) ? key : KeyNormalizer.Normalize(key);
}
>
public class LookupNormalizer : ILookupNormalizer
{
public string Normalize(string key)
{
return key.Normalize().ToLowerInvariant();
}
}