Value cannot be null. Parameter name: value, CreateIdentityAsync?

眉间皱痕 提交于 2019-11-30 01:44:03
user2536835

I faced the same issue while upgrading from ASP.NET Identity 1 to ASP.NET Identity 2 and I solved it by putting a random string in the field SecurityStamp.

I found this solution here.

I hope it works for you too.

As Sam mentioned in his comment for the previous answer, my solution to this problem was to make sure that the user I was creating in in the Seed method of the EF Migration had something in the SecurityStamp. Once I did that and did a update-database -force, I was able to log in just fine.

context.Users.AddOrUpdate(u => u.UserName,
                new ApplicationUser
                {
                    UserName = "demo",
                    Email = "demo@demo.com",
                    EmailConfirmed = true,
                    PhoneNumberConfirmed = true,
                    PasswordHash = password,
                    PhoneNumber = "111-222-3344",
                    SecurityStamp = Guid.NewGuid().ToString() //THIS IS WHAT I NEEDED
                });

If you created your user through some other means, you should be able to fix it by putting a string in the users db column via sql and have the same success.

In a similar way to Kevin, we were also experiencing this issue. It turns out that when seeding the database someone had forgotten to set the UserName property which produced this same error.

I had a more generic issue - some of my claims had Null values in the AspNetUserClaims table after a sql upgrade routine had run.

I solved the issue by setting the ClaimValues to an empty string.

For me it was overriding UserName field, in order to use my own Display attribute. I was using the following in my ApplicationUser class:

[Display(Name = "Whatever")]
public new string UserName { get; set; }

When I remove this, signin works as expected. I have also overriden Email and PhoneNumber but UserName causes the issue.

This problem kicked me around the office for a few hours.

This was the line causing the problem:

result = signinManager.PasswordSignIn(txtthecrmusername.Text, txtthecrmpassword.Text, RememberMe.Checked, shouldLockout:=False)

In the end, I'd added a custom field to AspNetUsers and left it null. In my haste I'd also forgotten to set it to nothing when creating users.

Custom user claims cannot be null but standard claims can.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!