我调用 CreateUserAndAccount 方法在用户名和密码中提供字符串。但我得到一个例外,说硬编码的字符串为空。这怎么可能!?!我在这里错过了什么?
代码:WebSecurity.CreateUserAndAccount("Admin", "Admin", null, false);
SQLEXCEPTION:无法将值 NULL 插入列 'UserPwd'、表 'servidb.dbo.User';列不允许空值。插入失败。
我也将表的名称从 UserProfile 更改为 User 和 Password 列。可能是这里的错误?
问候。
ps:我不知道还有什么代码要显示。如果需要更多信息,请询问。
编辑:其实我做到了:
WebSecurity.InitializeDatabaseConnection("connectionString", "User", "UserId", "UserName", autoCreateTables: true);
我检查了数据库,并使用该列创建了表用户。我的实体代码是这个
[Table("User")]
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
[Required]
public string UserName { get; set; }
[Required]
public string UserPwd { get; set; }
}