我正在调用CreateUserAndAccount方法,在用户名和密码中提供字符串。但是我得到了一个异常,说硬编码的字符串是空的。这怎么可能!?!我是不是漏掉了什么?
代码:WebSecurity.CreateUserAndAccount("Admin", "Admin", null, false);
SQLEXCEPTION:无法将值NULL插入到表‘servidb.dbo.User’的列'UserPwd‘中;列不允许为NULL。插入失败。
我还将表的名称从UserProfile更改为User和Password列。可能是这里的错误??
致以问候。
ps:我不知道代码还能显示什么。如果需要更多信息,请询问。
编辑:实际上我做到了:
WebSecurity.InitializeDatabaseConnection("connectionString", "User", "UserId", "UserName", autoCreateTables: true);
我检查了数据库,表User是用列创建的。我的实体代码是这个
[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; }
}发布于 2014-08-09 00:34:37
试试这个:
WebSecurity.CreateUserAndAccount("Admin", "Admin", new {UserPwd = ""}, false)第三个参数表示一个匿名对象,您可以使用该对象来提供Required字段,以便您的SQL值获得所需的所有非空值
发布于 2013-08-23 10:05:13
这可能是因为您更改了这些列的名称,WebSecurity自己知道要使用哪些列,它实际上使用自己生成的表,除了您的带有用户名的表。如果你正在使用互联网模板,它可能就在你的InitializeSimplemembership.cs中。
WebSecurity.InitializeDatabaseConnection([here database username],
[here database password], [here YOUR talbe name containing user name column],
[here user name column] , autoCreateTables: true);因此,您只创建了一个包含UserName列的表,其余的由WebSecurity在新表中创建。
https://stackoverflow.com/questions/18393487
复制相似问题