我正在 ASP.NET Core 2.1 中开发一个应用程序。我正在使用带有内置用户帐户的身份。现在我正在尝试在我遇到困难的这个应用程序中开发一个用户维护模块。我无法获取控制器内的数据。这是我的代码:
ApplicationDbContext.cs:
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
}
启动.cs:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<IdentityUser,IdentityRole>(config => {
config.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
services.AddMemoryCache();
services.AddSession();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddSessionStateTempDataProvider();
services.AddSingleton<IEmailSender, EmailSender>();
}
应用程序用户.cs:
public class ApplicationUser : IdentityUser
{
[Required]
public string FirstName { get; set; }
[Required]
public string Name { get; set; }
}
索引.cshtml:
@model IEnumerable<TestIdentity.Models.ApplicationUser>
@{
ViewData["Title"] = "Index";
}
<h2>Application users</h2>
@foreach (var item in Model)
{
<p>@item.Name</p>
}
_context.ApplicationUsers.ToListAsync()尽管我的 AspNetUsers 表中有数据,但没有返回任何结果。
侃侃尔雅
ABOUTYOU
相关分类