asp.net核心如何在寄存器标识中添加input.properties



你好,请帮帮我:D

在我下面的一个在身份寄存器中添加更多输入的教程中,他做到了图像1

看看第95行,他一开始有new Identity,然后改成了他的型号new ApplicationUser

我的问题是我的代码和这个代码不一样,请看这个

图像2

在第129-133行中,你可以看到它与图像一不同它是新的吗?

我应该怎么做?

如果能帮助的话,这是身份页面中注册页面中的OnPost方法

public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
returnUrl ??= Url.Content("~/");
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
if (ModelState.IsValid)
{
var user = CreateUser();
await _userStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);
await _emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None);
var result = await _userManager.CreateAsync(user, Input.Password);
if (result.Succeeded)
{
_logger.LogInformation("User created a new account with password.");
var userId = await _userManager.GetUserIdAsync(user);
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
var callbackUrl = Url.Page(
"/Account/ConfirmEmail",
pageHandler: null,
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
if (_userManager.Options.SignIn.RequireConfirmedAccount)
{
return RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl });
}
else
{
await _signInManager.SignInAsync(user, isPersistent: false);
return LocalRedirect(returnUrl);
}
}
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}
// If we got this far, something failed, redisplay form
return Page();
}
ApplicationUser只是简单地扩展了IdentityUser。

请参考:

https://adrientorris.github.io/aspnet-core/identity/extend-user-model.html#:~:text=ASP.NET%20Core%20Identity%20has%20a%20default%20implementation%20that,identity%20user%2C%20and%20add%20the%20properties%20you%20need.

最新更新