在ASP .NET Core 5的Individual Accounts模板中,用户类位于Areas/Identity/Data文件夹下的ApplicationUser.cs文件中。在这个类中,你可以找到关于用户账号的一些重要信息,例如用户的ID,用户名,邮箱地址,密码哈希值等等。
以下是ApplicationUser类的一个简单示例:
using Microsoft.AspNetCore.Identity;
namespace YourApplication.Areas.Identity.Data
{
public class ApplicationUser : IdentityUser
{
//添加额外的用户属性
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
}
在这个例子中,我们扩展了IdentityUser类,添加了一些额外的用户属性,例如名字,姓氏和年龄。这些属性可以在用户注册时被设置,也可以在以后的操作中修改。
要使用这个用户类,你需要在你的应用程序中使用Identity框架。在Startup.cs文件中,你需要添加以下代码:
using YourApplication.Areas.Identity.Data;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{
}
}
在这个例子中,我们扩展了IdentityDbContext类,并将ApplicationUser类作为类型参数传递。现在,你可以在你的应用程序中使用ApplicationUser类来查询和操作用户信息了。