UserManager.CreateIdentityAsync null reference

本文关键字:reference null CreateIdentityAsync UserManager | 更新日期: 2023-09-27 18:18:20

我试图修改自动创建的登录系统,当你在visual studio 2013 sp 3上创建一个新的mvc项目。当我注册我的用户时,我去

 await SignInAsync(user, isPersisten:false);

   private async Task SignInAsync(User user, bool isPersistent)
    {
        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
        var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
        AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
    }

即使我的用户对象是完整的信息和ApplicationCookie = ApplicationCookie我仍然得到NullReferenceException在UserManager.CreateIdentityAsync.

UserManager.CreateIdentityAsync null reference

刚刚有同样的问题,修复是更新ASP。NET标识从1.0到2.1。对我来说,这是两个NuGet包Microsoft.AspNet.Identity。Core microt.aspnet . identity . entityframework 。然后,我必须首先创建一个EF代码数据库迁移,它改变了几个ASP。. NET Identity数据库表,但这进行得很顺利,现在一切正常。