title: Migrate Identity Authentication from ASP.NET MVC to ASP.NET Web API
body: <p>I have a ASP.NET MVC web application and I want to register and login using angular. I'm calling a Login and Register Method on my WebAPI when the user wants to Login/Register. The problem is that I don't know how to transfer my MVC Login and Register in the AccountController to my WebAPI.</p>
  
  <p>My current Register method looks like this:</p>
  
  <pre><code>// POST api/RegisterApi
  public async Task&lt;HttpResponseMessage&gt; Post([FromBody]RegisterViewModel model)
  {
     if (!ModelState.IsValid)
     {
         return await this.BadRequest(this.ModelState).ExecuteAsync(new CancellationToken());
     }
  
     var user = new ApplicationUser
     {
         Email = model.Email,
         UserName = model.Email
     };
  
     IdentityResult result = await this.UserManager.CreateAsync(user, model.Password);
  
     if (!result.Succeeded)
     {
         return await this.GetErrorResult(result).ExecuteAsync(new CancellationToken());
     }
  
      // Auto login after register (successful user registration should return access_token)
      var loginResult = this.LoginUser(new LoginViewModel()
     {
         Email = model.Email,
         Password = model.Password
     }); 
  
      return await loginResult;
  }
  </code></pre>
  
  <p>My main issue is the following line:</p>
  
  <pre><code>IdentityResult result = await this.UserManager.CreateAsync(user, model.Password);
  </code></pre>
  
  <p>Somehow i can't call the CreateAsync-Method and I don't really know why.</p>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Task' does not contain a definition for 'CreateAsync'
    and no extension method 'CreateAsync' accepting a first argument of
    type 'Task</p>
  </blockquote>
  
  <p>Do you guys can give my any input on doing this properly? Everything I've seen so far seemed far too complicated for my problem.</p>
  
  <p>EDIT: Okay the error is solved, but now there's a new problem. The CreateAsync method does not Create a User and returns to the error function in my AngularJs. Do you guys have any suggestion why CreateAsync could fail?</p>