从历史上看,当我想在AspNetUsers表上添加一列或多列时,我遵循的工作流程如下:
1.创建一个ApplicationUser类,从中继承IdentityUser。
2.将新属性添加到应用程序用户类
3:更新applicationDbContext以从中继承:IdentityDbContext
4:在启动代码中更改对IdentityUser的任何引用,例如:Startup.cs / Global等
5:Add-Migration MigrationName
6:更新数据库
这将为新列生成Up / Down脚本,并将该列添加到我的数据库中。
但是,我已经启动了一个新的Blazor服务器端Web应用程序,并执行了上述步骤,但无济于事。
谁能看到我在这里缺少的东西吗?我过去做过如此多次,以至于我发现自己错过了一些东西很奇怪,但是一切皆有可能。希望有人可以提供帮助,请参阅下面有关为实现此目的而更改的代码。
应用程序数据库上下文代码:
namespace ExtendingBlazorIdentity.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
}
}
应用程序用户类别:
namespace ExtendingBlazorIdentity.Data
{
public class ApplicationUser : IdentityUser
{
string NickName { get; set; }
}
}
启动文件
namespace ExtendingBlazorIdentity
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<ApplicationUser>>();
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddSingleton<WeatherForecastService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
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.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
您的财产不公开。
public class ApplicationUser : IdentityUser
{
public string NickName { get; set; }
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句