Asp.Net Identity save user without email

Hagakurje

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?

trailmax

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.

edited at
0

Comments

0 comments
Login to comment

Related

How do I change an ASP.NET Identity user's email WITHOUT requiring an email confirmation?

Asp.net identity extra user information like email etc

Password reset without entering email (ASP.NET Identity)

Email confirmation and Password Policy Without ASP.NET Identity

Identity email with dash in Asp.Net Identity

Identity without individual user accounts in ASP.NET

How should I add a user email address for a user with ASP.NET Identity 2

Set email as username in ASP.NET Identity

Asp.net Identity 2.0 - Unique Email

ASP.NET Identity Register new user to use UserName as UserName not Email, but still not displaying who is logged in

How to reference ASP.Net Identity User Email property as Foreign Key

prevent users without confirmed email from logging in ASP.Net MVC with Identity 2

How to save user last login date if he was logged in with external login provider using ASP .Net Identity?

Check claims (email) before creating a new cookie, without asp. core identity store using asp net core social login

ASP.NET Identity, Register manual added user without deleting him

ASP.NET Core. How can i create an auth cookie without an identity user account?

ASP.NET Identity and SignalR getting user

ASP.NET Core Identity user groups

Asp.net Identity logout other user

How to edit a user in ASP.NET Identity

Updating user data - ASP.NET Identity

Verify user device in asp.net identity

ASP.NET Identity Update User - Nullreference

ASP.NET Identity - Extend available fields of User.Identity

Get user email from facebook in asp net

ASP.Net Core 2(.1.2) - Save user data without having to trust the client

Asp.net core identity change username/email

Confirming more than one email in Asp.net Identity core

ASP.NET Core Identity invalid token on confirmation email