I want to save user without email, like this:
var user = new ApplicationUser { UserName = model.Name };
var result = await UserManager.CreateAsync(user);
But I got error "Email cannot be null or empty". Is there any solution for this? Or it is impossible?
Identity depends on email as a way to reset user password.
However, ignoring email is not simple, but possible. You'll need to implement Microsoft.AspNet.Identity.IIdentityValidator
interface that ignores the lack of email:
namespace Microsoft.AspNet.Identity
{
/// <summary>
/// Used to validate an item
///
/// </summary>
/// <typeparam name="T"/>
public interface IIdentityValidator<in T>
{
/// <summary>
/// Validate the item
///
/// </summary>
/// <param name="item"/>
/// <returns/>
Task<IdentityResult> ValidateAsync(T item);
}
}
And then in ApplicationUserManager
assign your own implementation to property UserValidator
.
If you really need this, you can get the original source code for UserValidator
by decompiling Microsoft.AspNet.Identity.UserValidator
class and peeking into the existing source code and removing cheecking for email.
However, I'm not sure how the rest of the framework will react on lack of email on user. Probably you'll get exceptions in other operations.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments