[英]WebSecurity CreateUserAndAccount
我調用CreateUserAndAccount方法在用戶名和密碼中提供了字符串。 但是我得到一個例外,說硬編碼字符串為null。 這怎么可能!!! 我在這里想念什么嗎?
代碼: WebSecurity.CreateUserAndAccount("Admin", "Admin", null, false);
SQLEXCEPTION:無法將值NULL插入表“ servidb.dbo.User”的“ UserPwd”列中; 列不允許為空。 INSERT失敗。
我也將表的名稱從UserProfile更改為User and 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; }
}
可能是因為您更改了這些列名,WebSecurity知道自己要使用哪些列,它實際上使用了自己生成的表,但帶有用戶名的表除外。 如果您使用Internet模板,則可能在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在新表中創建。
嘗試這個:
WebSecurity.CreateUserAndAccount("Admin", "Admin", new {UserPwd = ""}, false)
第3個參數表示一個匿名對象,您可以使用該對象提供您的Required
字段,以便SQL獲取所需的所有非null值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.