title: Accessing UserManager outside AccountController
body: <p>I am trying to set the value of a column in <code>aspnetuser</code> table from a different controller (not <code>accountcontroller</code>). I have been trying to access <code>UserManager</code> but I can't figure our how to do it.</p>
  
  <p>So far I have tried the following in the controller I want to use it in:</p>
  
  <pre><code>    ApplicationUser u = UserManager.FindById(User.Identity.GetUserId());
      u.IsRegComplete = true;
      UserManager.Update(u);
  </code></pre>
  
  <p>This would not compile (I think because <code>UserManager</code> has not been instantiated the controller) </p>
  
  <p>I also tried to create a public method in the <code>AccountController</code> to accept the value I want to change the value to and do it there but I can't figure out how to call it. </p>
  
  <pre><code>public void setIsRegComplete(Boolean setValue)
  {
      ApplicationUser u = UserManager.FindById(User.Identity.GetUserId());
      u.IsRegComplete = setValue;
      UserManager.Update(u);
  
      return;
  }
  </code></pre>
  
  <p>How do you access and edit user data outside of the Account Controller? </p>
  
  <p>UPDATE:</p>
  
  <p>I tried to instantiate the UserManager in the other controller like so:</p>
  
  <pre><code>    var userManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(db));
      ApplicationUser u = userManager.FindById(User.Identity.GetUserId());
  </code></pre>
  
  <p>I the project complied (got a little excited) but when I ran the code I get the following error:</p>
  
  <pre><code>Additional information: The entity type ApplicationUser is not part of the model for the current context.
  </code></pre>
  
  <p>UPDATE 2:</p>
  
  <p>I have moved the function to the IdentityModel (don't ask I am clutching at straws here) like so:</p>
  
  <pre><code>   public class ApplicationUser : IdentityUser
      {
          public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager)
          {
              // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
              var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
              // Add custom user claims here
              return userIdentity;
          }
          public Boolean IsRegComplete { get; set; }
  
          public void SetIsRegComplete(string userId, Boolean valueToSet)
          {
  
              var userManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;());
              ApplicationUser u = new ApplicationUser();
              u = userManager.FindById(userId);
  
              u.IsRegComplete = valueToSet;
              return;
          }
      }
  </code></pre>
  
  <p>However I am still getting the following:</p>
  
  <pre><code>The entity type ApplicationUser is not part of the model for the current context.
  </code></pre>
  
  <p>There is also the following class in IdentitiesModels.cs:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("DefaultConnection", throwIfV1Schema: false)
      {
      }
  
      public static ApplicationDbContext Create()
      {
          return new ApplicationDbContext();
      }
  }
  </code></pre>
  
  <p>What am I doing wrong here? It feels like I am completely barking up the wrong tree. All I am trying to do is update a column in aspnetuser table from the action of a different controller (i.e not the AccountsController).</p>