私はすべてを検索しました。私のコードで何かが間違っている/見つからないと思います。AspNet.Identity CreateAsyncがCustomStoreを使用してuser.Idを返しません
私は、AspNet IDを操作するためのカスタムUserStoreを作成しました。私CreateAsync
コードは次のようになります。
public Task CreateAsync(ApplicationUser user)
{
var newUser = _permissionApiClient.Store(Mapper.Map<AccountDomainModel>(user));
// newUser does have the Id
// I would think I return newUser, but samples say to return null?
return Task.FromResult<Object>(null);
}
ときに私のAccountController.Register
火災、それはアカウントを作成しますが、私はuser.Id(私は確認コードを取得しようとする)必要がある場合、それは人口ではありません。
私は何が欠けているのか分かりません。 UserManager.CreateAsync
またはSignInManager.SignInAsync
にByRef
コールが送信されるはずですか?手動で何かする必要がありますか?
は、ここに私のコードのいくつかのより多くのです:
public class ApplicationUserManager : UserManager<ApplicationUser, int>
{
public ApplicationUserManager(IUserStore<ApplicationUser, int> store, IDataProtectionProvider dataProtectionProvider)
: base(store)
{
// Configure validation logic for usernames
UserValidator = new UserValidator<ApplicationUser, int>(this)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
// Configure validation logic for passwords
PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
// Configure user lockout defaults
UserLockoutEnabledByDefault = false;
//// Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
//// You can write your own provider and plug it in here.
EmailService = new EmailService();
SmsService = new SmsService();
if (dataProtectionProvider != null)
{
UserTokenProvider =
new DataProtectorTokenProvider<ApplicationUser, int>(dataProtectionProvider.Create("ASP.NET Identity"));
}
}
}
そして、私のAppliationUser:
public class ApplicationUser : IUser<int>
{
public int Id { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
/// <summary>
/// The salted/hashed form of the user password
/// </summary>
public virtual string PasswordHash { get; set; }
public bool IsEmailConfirmed { get; set; }
/// <summary>
/// Is two factor enabled for the user
/// </summary>
public virtual bool TwoFactorEnabled => false;
/// <summary>
/// Is lockout enabled for this user
/// </summary>
public virtual bool LockoutEnabled => false;
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
何が背景にありますか? OR/M? –
OR/MへのWebApi。 '_permissionApiClient.Store(Mapper.Map(user));'は入力されたIDを持つユーザオブジェクトを返します。 –