为什么我不能在混合身份验证项目中创建新用户

时间:2019-08-13 12:41:25

标签: c# asp.net-mvc-5

我正在尝试为混合身份验证项目创建用户。我正在使用 MixedAuthExtension.cs 。 我到达这条线时遇到问题  IdentityResult result = await UserManager.CreateAsync(user,model.Password); 但系统用户已创建,并且 AspNetUser

预先感谢您的帮助

当前代码同时创建系统用户和ASP.NET用户,但无法同步身份

[ValidateAntiForgeryToken]
[HttpPost]
public async Task<ActionResult> CreateSystemUser(RegisterViewModel model, string key)
{
    var _context = new RequestToFillDbContext();

    #region Initialise

    Initialise(_context);
    var password = SecurityHelper.GeneratePassword();
    UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(_context);
    UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
    UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager) { AllowOnlyAlphanumericUserNames = false };
    model.Password = password;
    model.ConfirmPassword = password;
    ModelState.Clear();

    #endregion
    string serviveNumber = model.ServiceNumber;

    if (!_context.SystemUsers.Any(s => s.EmailAddress == model.EmailAddress)
        && !_context.SystemUsers.Any(s => s.UserName == model.UserName))
    {
        if (ModelState.IsValid)
        {

            var emp = new RequestToFillApplicationHelper().GetEmployeeByServiceNumber(serviveNumber);
            model.Designation = emp.Designation;
            //TODO: Query Db for Id

            //var identityManager = new IdentityManager();
            var user = new ApplicationUser
            {
                UserName = model.UserName,
                Email = model.EmailAddress,
                EmailConfirmed = true,
                SystemUser = new SystemUser()
                {
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    UserName = model.UserName,
                    CompanyName = model.CompanyName,
                    Designation = model.Designation,
                    EmailAddress = model.EmailAddress,
                    IsTemporaryPassword = true,
                    //TempPasswordExpiryDateTime = DateTime.Now.AddHours(24),
                    SystemUserTypeId = model.SystemUserTypeId,
                    ServiceNumber = model.ServiceNumber,
                    IsActive = true,
                    IsDeleted = false,
                    IsLocked = false,
                    CreatedDateTime = DateTime.Now,
                    IsPasswordReset = false
                }
            };

            //db.SaveChanges();

            try
            {
                IdentityResult result = await UserManager.CreateAsync(user,model.Password);

                //Assign user to role

我得到

  

“找不到属性设置方法。”第258行

位于

以下
IdentityResult result = await UserManager.CreateAsync(user,model.Password);

0 个答案:

没有答案