我使用asp.net身份创建新用户但收到错误:
无法将值NULL插入列'Id',表'Mydb.dbo.AspNetUsers'; 列不允许空值.INSERT失败.\ r \n语句已终止
但是在这里我没有像AspNetUsers这样的表,而是我拥有自己的用户表.
代码: Web.config:2个连接字符串
<add name="myEntities" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=;initial catalog=mydb;user id=sa;password=sdfsdfsdf;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MyConnString" connectionString="data source=;initial catalog=Mydb;user id=sa;password=sdfsdfsdf;" providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)
IdentityModel.cs:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
this.SecurityStamp = Guid.NewGuid().ToString();
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public string Id { get; set; }
public …Run Code Online (Sandbox Code Playgroud)