相关疑难解决方法(0)

如何在我的自定义表而不是aspnet用户中使用哈希密码保存新记录?

我使用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=&quot;data source=;initial catalog=mydb;user id=sa;password=sdfsdfsdf;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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)

c# asp.net asp.net-mvc owin asp.net-identity

12
推荐指数
1
解决办法
1347
查看次数

标签 统计

asp.net ×1

asp.net-identity ×1

asp.net-mvc ×1

c# ×1

owin ×1