【发布时间】:2019-11-16 03:42:15
【问题描述】:
我是实体框架的新手。 我正在开发一个 web 应用程序,我想为一个 Angular 站点创建一个用户身份验证模块。 用户登录完美。当我尝试添加用户角色时,我收到以下错误消息:
我收到以下错误: error
我使用 JWT 令牌作为身份验证器。 和 Microsoft.IdentityModel。
我的代码: 启动.cs 身份服务:
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<WebShopContext>();
JWT 自动服务:
var key = Encoding.UTF8.GetBytes(Configuration["ApplicationSettings:JWT_Secret"]);
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(x=> {
x.RequireHttpsMetadata = false;
x.SaveToken = false;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false,
ClockSkew = TimeSpan.Zero
};
});
}
我的 ApplicationRole 模型:
public class ApplicationRole : IdentityRole
{
public ApplicationRole() : base() { }
public ApplicationRole(string name) : base(name) { }
public string Description { get; set; }
}
}
我的 ApplicationUser 模型:
public class ApplicationUser : IdentityUser
{
[Column(TypeName="nvarchar(150)")]
public string FullName { get; set; }
[Column(TypeName = "nvarchar(100)")]
public string FirstName { get; set; }
[Column(TypeName = "nvarchar(100)")]
public string LastName { get; set; }
}
我完全不知道。我怎么解决这个问题。请帮帮我。
【问题讨论】:
-
您使用的是哪个版本的 .Net Core?
-
.Net core 2.2版 Entity framework core 2.2.4版
标签: c# entity-framework asp.net-core .net-core entity-framework-core