Я работаю над базовым проектом MVC, в значительной степени из коробки с небольшими улучшениями. Поэтому я немного изменил пользовательские свойства, но не слишком ... но, похоже, с тех пор он больше не работает. Я сделал то же самое раньше, не сталкиваясь с ошибками. Есть идеи, где я ошибся ??
IdentityModels:
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
//public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public string DateOfBirth { get; set; }
//public string Email { get; set; }
public string PhoneNumberPrefix { get; set; }
public string PhoneNumberSuffix { get; set; }
//public string PhoneNumber { get; set; }
public bool PhoneNumberVerified { get; set; }
public string BillingAddress { get; set; }
public bool BillingAddressIsShippingAddress { get; set; }
public string ShippingAddress { get; set; }
public string VATNumber { get; set; }
public string PreferredLanguage { get; set; }
public DateTime RegisteredDateTime { get; set; }
public string RegisteredLatitude { get; set; }
public string RegisteredLongitude { get; set; }
public string RegisteredLocation { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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;
}
}
public class UserDbContext : IdentityDbContext<ApplicationUser>
{
public UserDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static UserDbContext Create()
{
return new UserDbContext();
}
}
AccountController:
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
// define variables
var userID = User.Identity.GetUserId();
DateTime nowUTC = DateTime.Now.ToUniversalTime();
DateTime nowLocal = DateTime.Now.ToLocalTime();
// check model state and submit form
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
UserName = model.UserName,
FirstName = model.FirstName,
LastName = model.LastName,
Gender = model.Gender,
DateOfBirth = model.DateOfBirth,
Email = model.Email,
PhoneNumberPrefix = model.PhoneNumberPrefix,
PhoneNumberSuffix = model.PhoneNumberSuffix,
PhoneNumber = model.PhoneNumberPrefix + model.PhoneNumberSuffix,
BillingAddress = model.BillingAddress,
VATNumber = "MwSt-Nummer",
PreferredLanguage = model.PreferredLanguage,
RegisteredDateTime = nowUTC,
RegisteredLatitude = model.RegisteredLatitude,
RegisteredLongitude = model.RegisteredLongitude,
RegisteredLocation = model.RegisteredLocation
};
// send confirmation email
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new
{
userId = user.Id,
code /*= code*/
}, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Bestätige Dein Konto", "Bitte bestätige Dein Konto indem Du <a href=\"" + callbackUrl + "\">hier</a> klickst.");
ViewBag.Message = "Fast geschafft! Du hast eine Email mit weiteApplicationDbContextren Instruktionen erhalten um die Anmeldung abzuschliessen.";
// track user activity: post method includes activity name and timestamp along with location
var SUCCESS = new UserActivities
{
UserID = userID,
ActivityName = "Register_Success",
ActivityTimeStampUTC = nowUTC,
ActivityLatitude = model.RegisteredLatitude,
ActivityLongitude = model.RegisteredLongitude,
ActivityLocation = model.RegisteredLocation
};
DATADB.UserActivityList.Add(SUCCESS);
DATADB.SaveChanges();
return View("PostRegistration");
}
AddErrors(result);
}
var FAILURE = new UserActivities
{
UserID = userID,
ActivityName = "Register_Failure",
ActivityTimeStampUTC = nowUTC,
ActivityLatitude = model.RegisteredLatitude,
ActivityLongitude = model.RegisteredLongitude,
ActivityLocation = model.RegisteredLocation
};
DATADB.UserActivityList.Add(FAILURE);
DATADB.SaveChanges();
// repopulate dropdownlists
ViewBag.gender = DATADB.GenderList.Select(m => new SelectListItem()
{
Text = m.Gender,
Value = m.Gender
}).ToList();
ViewBag.countryCode = DATADB.CountryCodeList.Select(m => new SelectListItem()
{
Text = m.CountryCode,
Value = m.CountryCode
}).ToList();
ViewBag.preferredLanguage = DATADB.LanguageList.Select(m => new SelectListItem()
{
Text = m.Language,
Value = m.Language
}).ToList();
return View(model);
}