Daniel Gustafsson
Daniel Gustafsson

Reputation: 1817

UserManager.CreateIdentityAsync null reference

Im trying to modify the loginsystem that auto-creates when you create a new mvc project on visual studio 2013 sp 3. When i register my user i go to

 await SignInAsync(user, isPersisten:false);

Which goes to:

   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);
    }

Even though my user object is full with info and the ApplicationCookie = ApplicationCookie i still get NullReferenceException on UserManager.CreateIdentityAsync.

Upvotes: 2

Views: 1508

Answers (1)

Andy Mehalick
Andy Mehalick

Reputation: 993

Just had this same problem, the fix was updating ASP.NET Identity from 1.0 to 2.1. For me this was two NuGet packages Microsoft.AspNet.Identity.Core and Microsoft.AspNet.Identity.EntityFramework. I then had to create one EF code first database migration that altered several of the ASP.NET Identity database tables, but this went smoothly enough and now everything works.

Upvotes: 2

Related Questions