На основе Microsoft Learn It Tep добавить пользовательские данные пользователя пользователям, но где бы я ни старался использовать WebApp1user, я столкнулся с этой ошибкой:
InvalidoperationException: No Service for Type 'microsoft.aspnetCore.ident.UserManager`1 [microsoft.aspnetcore.ident.Idenity. /> webapp1user: < /p>
using Microsoft.AspNetCore.Identity;
namespace WebApp1.Areas.Identity.Data
{
public partial class WebApp1User : IdentityUser
{
[PersonalData]
public string? Name { get; set; }
[PersonalData]
public DateTime DOB { get; set; }
}
}
< /code>
program.cs:
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using WebApp1.Areas.Identity.Data;
using WebApp1.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
//builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true)
// .AddEntityFrameworkStores();
var connectionString2 = builder.Configuration.GetConnectionString("WebApp1ContextConnection");
builder.Services.AddDbContext(options => options.UseSqlServer(connectionString2));
builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores();
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
< /code>
В файле Program.cs, когда я пытаюсь использовать WebApp1user в качестве идентификации по умолчанию:
builder.services.adddefaultidentity(options => options.signin.requireconfirmedaccount = true)
. /> InvalidoperationException: без службы для типа 'microsoft.aspnetcore.identity.usermanager`1 [microsoft.aspnetcore.identity.identityuser]' есть < /p>
Подробнее здесь: https://stackoverflow.com/questions/797 ... ntity-user